[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> |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10 | #include <limits> |
[email protected] | 5285d97 | 2011-10-18 18:56:34 | [diff] [blame] | 11 | #include <string> |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 12 | #include <utility> |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 13 | #include <vector> |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 14 | |
[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" |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 20 | #include "base/macros.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 21 | #include "base/memory/scoped_ptr.h" |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 22 | #include "base/memory/weak_ptr.h" |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 23 | #include "base/run_loop.h" |
[email protected] | 125ef48 | 2013-06-11 18:32:47 | [diff] [blame] | 24 | #include "base/strings/string_util.h" |
[email protected] | 750b2f3c | 2013-06-07 18:41:05 | [diff] [blame] | 25 | #include "base/strings/utf_string_conversions.h" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 26 | #include "base/test/test_file_util.h" |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 27 | #include "base/thread_task_runner_handle.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 28 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 29 | #include "net/base/chunked_upload_data_stream.h" |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 30 | #include "net/base/completion_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 31 | #include "net/base/elements_upload_data_stream.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 32 | #include "net/base/load_timing_info.h" |
| 33 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 34 | #include "net/base/net_errors.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 35 | #include "net/base/proxy_delegate.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 36 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 37 | #include "net/base/test_completion_callback.h" |
[email protected] | 42fdb45 | 2012-11-01 12:44:40 | [diff] [blame] | 38 | #include "net/base/test_data_directory.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 39 | #include "net/base/test_proxy_delegate.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 40 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 41 | #include "net/base/upload_file_element_reader.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 42 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 43 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 44 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 45 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 46 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 47 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 48 | #include "net/http/http_auth_handler_ntlm.h" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 49 | #include "net/http/http_auth_scheme.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 50 | #include "net/http/http_basic_state.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 51 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 52 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 53 | #include "net/http/http_network_session_peer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 54 | #include "net/http/http_request_headers.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 55 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 56 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 57 | #include "net/http/http_stream_factory.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 58 | #include "net/http/http_stream_parser.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 59 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 60 | #include "net/log/net_log.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 61 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 62 | #include "net/log/test_net_log_entry.h" |
| 63 | #include "net/log/test_net_log_util.h" |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 64 | #include "net/proxy/mock_proxy_resolver.h" |
[email protected] | 51fff29d | 2008-12-19 22:17:53 | [diff] [blame] | 65 | #include "net/proxy/proxy_config_service_fixed.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 66 | #include "net/proxy/proxy_info.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 67 | #include "net/proxy/proxy_resolver.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 68 | #include "net/proxy/proxy_server.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 69 | #include "net/proxy/proxy_service.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 70 | #include "net/socket/client_socket_factory.h" |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 71 | #include "net/socket/client_socket_pool.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 72 | #include "net/socket/client_socket_pool_manager.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 73 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 74 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 75 | #include "net/socket/next_proto.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 76 | #include "net/socket/socket_test_util.h" |
| 77 | #include "net/socket/ssl_client_socket.h" |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 78 | #include "net/spdy/spdy_framer.h" |
| 79 | #include "net/spdy/spdy_session.h" |
| 80 | #include "net/spdy/spdy_session_pool.h" |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 81 | #include "net/spdy/spdy_test_util_common.h" |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 82 | #include "net/ssl/default_channel_id_store.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 83 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 84 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 85 | #include "net/ssl/ssl_config_service_defaults.h" |
| 86 | #include "net/ssl/ssl_info.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 87 | #include "net/ssl/ssl_private_key.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 88 | #include "net/test/cert_test_util.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 89 | #include "net/websockets/websocket_handshake_stream_base.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 90 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 91 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 92 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 93 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 94 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 95 | using base::ASCIIToUTF16; |
| 96 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 97 | //----------------------------------------------------------------------------- |
| 98 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 99 | namespace net { |
| 100 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 101 | namespace { |
| 102 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 103 | enum TestCase { |
| 104 | // Test using the SPDY/3.1 protocol. |
| 105 | kTestCaseSPDY31, |
| 106 | |
| 107 | // Test using the HTTP/2 protocol, without specifying a stream |
| 108 | // dependency based on the RequestPriority. |
| 109 | kTestCaseHTTP2NoPriorityDependencies, |
| 110 | |
| 111 | // Test using the HTTP/2 protocol, specifying a stream |
| 112 | // dependency based on the RequestPriority. |
| 113 | kTestCaseHTTP2PriorityDependencies |
| 114 | }; |
| 115 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 116 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 117 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 118 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 119 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 120 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 121 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 122 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 123 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 124 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 125 | const base::string16 kSecond(ASCIIToUTF16("second")); |
| 126 | const base::string16 kTestingNTLM(ASCIIToUTF16("testing-ntlm")); |
| 127 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 128 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 129 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
| 130 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 131 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 132 | } |
| 133 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 134 | int GetIdleSocketCountInSSLSocketPool(HttpNetworkSession* session) { |
| 135 | return session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 136 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 137 | } |
| 138 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 139 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
| 140 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 141 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 142 | } |
| 143 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 144 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 145 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 146 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 147 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 148 | if (!params) |
| 149 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 150 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 151 | if (!params->GetList("headers", &header_list)) |
| 152 | return false; |
| 153 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 154 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 155 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 156 | return true; |
| 157 | } |
| 158 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 159 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 160 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 161 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 162 | EXPECT_TRUE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 163 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 164 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 165 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 166 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 167 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 168 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 169 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 170 | |
| 171 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 172 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 173 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 174 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 175 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 176 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 177 | } |
| 178 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 179 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 180 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 181 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 182 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 183 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 184 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 185 | |
| 186 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 187 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 188 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 189 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 190 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 191 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 192 | load_timing_info.send_start); |
| 193 | |
| 194 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 195 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 196 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 197 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 198 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 199 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 203 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 204 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 205 | EXPECT_TRUE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 206 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 207 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 208 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 209 | |
| 210 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 211 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 212 | load_timing_info.proxy_resolve_end); |
| 213 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 214 | load_timing_info.send_start); |
| 215 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 216 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 217 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 218 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 219 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 220 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 224 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 225 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 226 | int connect_timing_flags) { |
| 227 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 228 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 229 | |
| 230 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 231 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 232 | load_timing_info.proxy_resolve_end); |
| 233 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 234 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 235 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 236 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 237 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 238 | load_timing_info.send_start); |
| 239 | |
| 240 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 241 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 242 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 243 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 244 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 245 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 246 | } |
| 247 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 248 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 249 | headers->SetHeader("Connection", "Upgrade"); |
| 250 | headers->SetHeader("Upgrade", "websocket"); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 251 | headers->SetHeader("Origin", "http://www.example.org"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 252 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
| 253 | headers->SetHeader("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ=="); |
| 254 | } |
| 255 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 256 | scoped_ptr<HttpNetworkSession> CreateSession( |
| 257 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 258 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 259 | } |
| 260 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 261 | } // namespace |
| 262 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 263 | class HttpNetworkTransactionTest |
| 264 | : public PlatformTest, |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 265 | public ::testing::WithParamInterface<TestCase> { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 266 | public: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 267 | virtual ~HttpNetworkTransactionTest() { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 268 | // Important to restore the per-pool limit first, since the pool limit must |
| 269 | // always be greater than group limit, and the tests reduce both limits. |
| 270 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 271 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 272 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 273 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 274 | } |
| 275 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 276 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 277 | HttpNetworkTransactionTest() |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 278 | : spdy_util_(GetProtocol(), GetDependenciesFromPriority()), |
| 279 | session_deps_(GetProtocol()), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 280 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
| 281 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 282 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 283 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
rdsmith | 2e54d1f | 2016-03-21 19:48:17 | [diff] [blame] | 284 | session_deps_.enable_priority_dependencies = GetDependenciesFromPriority(); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 285 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 286 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 287 | struct SimpleGetHelperResult { |
| 288 | int rv; |
| 289 | std::string status_line; |
| 290 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 291 | int64_t total_received_bytes; |
| 292 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 293 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 294 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 295 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 296 | }; |
| 297 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 298 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 299 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 300 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 301 | } |
| 302 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 303 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 304 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 305 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 306 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 307 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 308 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 309 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 310 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 311 | } |
| 312 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 313 | NextProto GetProtocol() const { |
| 314 | return GetParam() == kTestCaseSPDY31 ? kProtoSPDY31 : kProtoHTTP2; |
| 315 | } |
| 316 | |
| 317 | bool GetDependenciesFromPriority() const { |
| 318 | return GetParam() == kTestCaseHTTP2PriorityDependencies; |
| 319 | } |
| 320 | |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 321 | const char* GetAlternateProtocolFromParam() { |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 322 | return AlternateProtocolToString( |
| 323 | AlternateProtocolFromNextProto(GetProtocol())); |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 324 | } |
| 325 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 326 | std::string GetAlternativeServiceHttpHeader() { |
| 327 | return std::string("Alt-Svc: ") + GetAlternateProtocolFromParam() + |
| 328 | "=\"www.example.com:443\"\r\n"; |
| 329 | } |
| 330 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 331 | std::string GetAlternateProtocolHttpHeader() { |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 332 | return std::string("Alternate-Protocol: 443:") + |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 333 | GetAlternateProtocolFromParam() + "\r\n"; |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 334 | } |
| 335 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 336 | // Either |write_failure| specifies a write failure or |read_failure| |
| 337 | // specifies a read failure when using a reused socket. In either case, the |
| 338 | // failure should cause the network transaction to resend the request, and the |
| 339 | // other argument should be NULL. |
| 340 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 341 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 342 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 343 | // Either |write_failure| specifies a write failure or |read_failure| |
| 344 | // specifies a read failure when using a reused socket. In either case, the |
| 345 | // failure should cause the network transaction to resend the request, and the |
| 346 | // other argument should be NULL. |
| 347 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 348 | const MockRead* read_failure, |
| 349 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 350 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 351 | SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
| 352 | size_t data_count) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 353 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 354 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 355 | HttpRequestInfo request; |
| 356 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 357 | request.url = GURL("http://www.example.org/"); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 358 | request.load_flags = 0; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 359 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 360 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 361 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 362 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 363 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 364 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 365 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 366 | for (size_t i = 0; i < data_count; ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 367 | session_deps_.socket_factory->AddSocketDataProvider(data[i]); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 368 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 369 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 370 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 371 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 372 | EXPECT_TRUE(log.bound().IsCapturing()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 373 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 374 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 375 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 376 | out.rv = callback.WaitForResult(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 377 | out.total_received_bytes = trans->GetTotalReceivedBytes(); |
| 378 | out.total_sent_bytes = trans->GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 379 | |
| 380 | // Even in the failure cases that use this function, connections are always |
| 381 | // successfully established before the error. |
| 382 | EXPECT_TRUE(trans->GetLoadTimingInfo(&out.load_timing_info)); |
| 383 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 384 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 385 | if (out.rv != OK) |
| 386 | return out; |
| 387 | |
| 388 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 389 | // Can't use ASSERT_* inside helper functions like this, so |
| 390 | // return an error. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 391 | if (response == NULL || response->headers.get() == NULL) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 392 | out.rv = ERR_UNEXPECTED; |
| 393 | return out; |
| 394 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 395 | out.status_line = response->headers->GetStatusLine(); |
| 396 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 397 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 398 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 399 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 400 | bool got_endpoint = |
| 401 | trans->GetRemoteEndpoint(&out.remote_endpoint_after_start); |
| 402 | EXPECT_EQ(got_endpoint, |
| 403 | out.remote_endpoint_after_start.address().size() > 0); |
| 404 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 405 | rv = ReadTransaction(trans.get(), &out.response_data); |
| 406 | EXPECT_EQ(OK, rv); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 407 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 408 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 409 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 410 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 411 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
[email protected] | 169d001 | 2010-05-10 23:20:12 | [diff] [blame] | 412 | NetLog::PHASE_NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 413 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 414 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 415 | NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 416 | NetLog::PHASE_NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 417 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 418 | std::string line; |
| 419 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 420 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 421 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 422 | HttpRequestHeaders request_headers; |
| 423 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 424 | std::string value; |
| 425 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 426 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 427 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 428 | EXPECT_EQ("keep-alive", value); |
| 429 | |
| 430 | std::string response_headers; |
| 431 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 432 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 433 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 434 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 435 | out.total_received_bytes = trans->GetTotalReceivedBytes(); |
| 436 | // The total number of sent bytes should not have changed. |
| 437 | EXPECT_EQ(out.total_sent_bytes, trans->GetTotalSentBytes()); |
| 438 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 439 | trans->GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 440 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 441 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 442 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 443 | SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 444 | size_t reads_count) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 445 | MockWrite data_writes[] = { |
| 446 | MockWrite("GET / HTTP/1.1\r\n" |
| 447 | "Host: www.example.org\r\n" |
| 448 | "Connection: keep-alive\r\n\r\n"), |
| 449 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 450 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 451 | StaticSocketDataProvider reads(data_reads, reads_count, data_writes, |
| 452 | arraysize(data_writes)); |
| 453 | StaticSocketDataProvider* data[] = {&reads}; |
| 454 | SimpleGetHelperResult out = SimpleGetHelperForData(data, 1); |
| 455 | |
| 456 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 457 | out.total_sent_bytes); |
| 458 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 459 | } |
| 460 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 461 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 462 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 463 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 464 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 465 | |
| 466 | void BypassHostCacheOnRefreshHelper(int load_flags); |
| 467 | |
| 468 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 469 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 470 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 471 | SpdySessionDependencies session_deps_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 472 | |
| 473 | // Original socket limits. Some tests set these. Safest to always restore |
| 474 | // them once each test has been run. |
| 475 | int old_max_group_sockets_; |
| 476 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 477 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 478 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 479 | INSTANTIATE_TEST_CASE_P(ProtoPlusDepend, |
bnc | 57685ae6 | 2015-03-10 21:27:20 | [diff] [blame] | 480 | HttpNetworkTransactionTest, |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 481 | testing::Values(kTestCaseSPDY31, |
| 482 | kTestCaseHTTP2NoPriorityDependencies, |
| 483 | kTestCaseHTTP2PriorityDependencies)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 484 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 485 | namespace { |
| 486 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 487 | class BeforeNetworkStartHandler { |
| 488 | public: |
| 489 | explicit BeforeNetworkStartHandler(bool defer) |
| 490 | : defer_on_before_network_start_(defer), |
| 491 | observed_before_network_start_(false) {} |
| 492 | |
| 493 | void OnBeforeNetworkStart(bool* defer) { |
| 494 | *defer = defer_on_before_network_start_; |
| 495 | observed_before_network_start_ = true; |
| 496 | } |
| 497 | |
| 498 | bool observed_before_network_start() const { |
| 499 | return observed_before_network_start_; |
| 500 | } |
| 501 | |
| 502 | private: |
| 503 | const bool defer_on_before_network_start_; |
| 504 | bool observed_before_network_start_; |
| 505 | |
| 506 | DISALLOW_COPY_AND_ASSIGN(BeforeNetworkStartHandler); |
| 507 | }; |
| 508 | |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 509 | class BeforeProxyHeadersSentHandler { |
| 510 | public: |
| 511 | BeforeProxyHeadersSentHandler() |
| 512 | : observed_before_proxy_headers_sent_(false) {} |
| 513 | |
[email protected] | 1252d42f | 2014-07-01 21:20:20 | [diff] [blame] | 514 | void OnBeforeProxyHeadersSent(const ProxyInfo& proxy_info, |
| 515 | HttpRequestHeaders* request_headers) { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 516 | observed_before_proxy_headers_sent_ = true; |
| 517 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 518 | } |
| 519 | |
| 520 | bool observed_before_proxy_headers_sent() const { |
| 521 | return observed_before_proxy_headers_sent_; |
| 522 | } |
| 523 | |
| 524 | std::string observed_proxy_server_uri() const { |
| 525 | return observed_proxy_server_uri_; |
| 526 | } |
| 527 | |
| 528 | private: |
| 529 | bool observed_before_proxy_headers_sent_; |
| 530 | std::string observed_proxy_server_uri_; |
| 531 | |
| 532 | DISALLOW_COPY_AND_ASSIGN(BeforeProxyHeadersSentHandler); |
| 533 | }; |
| 534 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 535 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 536 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 537 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 538 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 539 | const int sizeof_row = strlen(row); |
| 540 | const int num_rows = static_cast<int>( |
| 541 | ceil(static_cast<float>(size) / sizeof_row)); |
| 542 | const int sizeof_data = num_rows * sizeof_row; |
| 543 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 544 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 545 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 546 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 547 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 548 | } |
| 549 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 550 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 551 | // Alternative functions that eliminate randomness and dependency on the local |
| 552 | // host name so that the generated NTLM messages are reproducible. |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 553 | void MockGenerateRandom1(uint8_t* output, size_t n) { |
| 554 | static const uint8_t bytes[] = {0x55, 0x29, 0x66, 0x26, |
| 555 | 0x6b, 0x9c, 0x73, 0x54}; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 556 | static size_t current_byte = 0; |
| 557 | for (size_t i = 0; i < n; ++i) { |
| 558 | output[i] = bytes[current_byte++]; |
| 559 | current_byte %= arraysize(bytes); |
| 560 | } |
| 561 | } |
| 562 | |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 563 | void MockGenerateRandom2(uint8_t* output, size_t n) { |
| 564 | static const uint8_t bytes[] = {0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, |
| 565 | 0x70, 0xa1, 0x4e, 0xe7, 0x87, 0x45, |
| 566 | 0x31, 0x5b, 0xd3, 0x1f}; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 567 | static size_t current_byte = 0; |
| 568 | for (size_t i = 0; i < n; ++i) { |
| 569 | output[i] = bytes[current_byte++]; |
| 570 | current_byte %= arraysize(bytes); |
| 571 | } |
| 572 | } |
| 573 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 574 | std::string MockGetHostName() { |
| 575 | return "WTC-WIN7"; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 576 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 577 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 578 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 579 | template<typename ParentPool> |
| 580 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 581 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 582 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 583 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 584 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 585 | const std::string last_group_name_received() const { |
| 586 | return last_group_name_; |
| 587 | } |
| 588 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 589 | int RequestSocket(const std::string& group_name, |
| 590 | const void* socket_params, |
| 591 | RequestPriority priority, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 592 | ClientSocketPool::RespectLimits respect_limits, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 593 | ClientSocketHandle* handle, |
| 594 | const CompletionCallback& callback, |
| 595 | const BoundNetLog& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 596 | last_group_name_ = group_name; |
| 597 | return ERR_IO_PENDING; |
| 598 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 599 | void CancelRequest(const std::string& group_name, |
| 600 | ClientSocketHandle* handle) override {} |
| 601 | void ReleaseSocket(const std::string& group_name, |
| 602 | scoped_ptr<StreamSocket> socket, |
| 603 | int id) override {} |
| 604 | void CloseIdleSockets() override {} |
| 605 | int IdleSocketCount() const override { return 0; } |
| 606 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 607 | return 0; |
| 608 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 609 | LoadState GetLoadState(const std::string& group_name, |
| 610 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 611 | return LOAD_STATE_IDLE; |
| 612 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 613 | base::TimeDelta ConnectionTimeout() const override { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 614 | return base::TimeDelta(); |
| 615 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 616 | |
| 617 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 618 | std::string last_group_name_; |
| 619 | }; |
| 620 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 621 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 622 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 623 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 624 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 625 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 626 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 627 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 628 | CaptureGroupNameSSLSocketPool; |
| 629 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 630 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 631 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 632 | HostResolver* host_resolver, |
| 633 | CertVerifier* /* cert_verifier */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 634 | : ParentPool(0, 0, host_resolver, NULL, NULL) { |
| 635 | } |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 636 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 637 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 638 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 639 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 640 | CertVerifier* /* cert_verifier */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 641 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL) { |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 642 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 643 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 644 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 645 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 646 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 647 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 648 | : SSLClientSocketPool(0, |
| 649 | 0, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 650 | cert_verifier, |
| 651 | NULL, |
| 652 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 653 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 654 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 655 | std::string(), |
| 656 | NULL, |
| 657 | NULL, |
| 658 | NULL, |
| 659 | NULL, |
| 660 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 661 | NULL) { |
| 662 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 663 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 664 | //----------------------------------------------------------------------------- |
| 665 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 666 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 667 | // configured for common cases. |
| 668 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 669 | if (!auth_challenge) |
| 670 | return false; |
| 671 | EXPECT_FALSE(auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 672 | EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 673 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 674 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 675 | return true; |
| 676 | } |
| 677 | |
| 678 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 679 | if (!auth_challenge) |
| 680 | return false; |
| 681 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 682 | EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString()); |
| 683 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 684 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 685 | return true; |
| 686 | } |
| 687 | |
| 688 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 689 | if (!auth_challenge) |
| 690 | return false; |
| 691 | EXPECT_FALSE(auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 692 | EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 693 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 694 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 695 | return true; |
| 696 | } |
| 697 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 698 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 699 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 700 | if (!auth_challenge) |
| 701 | return false; |
| 702 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 703 | EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString()); |
| 704 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 705 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 706 | return true; |
| 707 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 708 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 709 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 710 | } // namespace |
| 711 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 712 | TEST_P(HttpNetworkTransactionTest, Basic) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 713 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 714 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 715 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 716 | } |
| 717 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 718 | TEST_P(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 719 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 720 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 721 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 722 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 723 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 724 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 725 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 726 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 727 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 728 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 729 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 730 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 731 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 732 | |
| 733 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | // Response with no status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 737 | TEST_P(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 738 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 739 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 740 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 741 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 742 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 743 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 744 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 745 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 746 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 747 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 748 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 752 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 753 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 754 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 755 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 756 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 757 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 758 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 759 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 760 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 761 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 762 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 763 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 767 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 768 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 769 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 770 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 771 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 772 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 773 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 774 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 775 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 776 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 777 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 778 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | // 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] | 782 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 783 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 784 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 785 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 786 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 787 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 788 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 789 | EXPECT_EQ(OK, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 790 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 791 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 792 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 793 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 797 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 798 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 799 | MockRead("\n"), |
| 800 | MockRead("\n"), |
| 801 | MockRead("Q"), |
| 802 | MockRead("J"), |
| 803 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 804 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 805 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 806 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 807 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 808 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 809 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 810 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 811 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 812 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | // Close the connection before enough bytes to have a status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 816 | TEST_P(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 817 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 818 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 819 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 820 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 821 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 822 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 823 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 824 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 825 | EXPECT_EQ("HTT", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 826 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 827 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 828 | } |
| 829 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 830 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 831 | // persistent connection. The response should still terminate since a 204 |
| 832 | // cannot have a response body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 833 | TEST_P(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 834 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 835 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 836 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 837 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 838 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 839 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 840 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 841 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 842 | EXPECT_EQ(OK, out.rv); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 843 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 844 | EXPECT_EQ("", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 845 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 846 | int64_t response_size = reads_size - strlen(junk); |
| 847 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 848 | } |
| 849 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 850 | // A simple request using chunked encoding with some extra data after. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 851 | TEST_P(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 852 | std::string final_chunk = "0\r\n\r\n"; |
| 853 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 854 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 855 | MockRead data_reads[] = { |
| 856 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 857 | MockRead("5\r\nHello\r\n"), |
| 858 | MockRead("1\r\n"), |
| 859 | MockRead(" \r\n"), |
| 860 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 861 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 862 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 863 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 864 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 865 | arraysize(data_reads)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 866 | EXPECT_EQ(OK, out.rv); |
| 867 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 868 | EXPECT_EQ("Hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 869 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 870 | int64_t response_size = reads_size - extra_data.size(); |
| 871 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 872 | } |
| 873 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 874 | // Next tests deal with http://crbug.com/56344. |
| 875 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 876 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 877 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 878 | MockRead data_reads[] = { |
| 879 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 880 | MockRead("Content-Length: 10\r\n"), |
| 881 | MockRead("Content-Length: 5\r\n\r\n"), |
| 882 | }; |
| 883 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 884 | arraysize(data_reads)); |
| 885 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 886 | } |
| 887 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 888 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 889 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 890 | MockRead data_reads[] = { |
| 891 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 892 | MockRead("Content-Length: 5\r\n"), |
| 893 | MockRead("Content-Length: 5\r\n\r\n"), |
| 894 | MockRead("Hello"), |
| 895 | }; |
| 896 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 897 | arraysize(data_reads)); |
| 898 | EXPECT_EQ(OK, out.rv); |
| 899 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 900 | EXPECT_EQ("Hello", out.response_data); |
| 901 | } |
| 902 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 903 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 904 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 905 | // More than 2 dupes. |
| 906 | { |
| 907 | MockRead data_reads[] = { |
| 908 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 909 | MockRead("Content-Length: 5\r\n"), |
| 910 | MockRead("Content-Length: 5\r\n"), |
| 911 | MockRead("Content-Length: 5\r\n\r\n"), |
| 912 | MockRead("Hello"), |
| 913 | }; |
| 914 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 915 | arraysize(data_reads)); |
| 916 | EXPECT_EQ(OK, out.rv); |
| 917 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 918 | EXPECT_EQ("Hello", out.response_data); |
| 919 | } |
| 920 | // HTTP/1.0 |
| 921 | { |
| 922 | MockRead data_reads[] = { |
| 923 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 924 | MockRead("Content-Length: 5\r\n"), |
| 925 | MockRead("Content-Length: 5\r\n"), |
| 926 | MockRead("Content-Length: 5\r\n\r\n"), |
| 927 | MockRead("Hello"), |
| 928 | }; |
| 929 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 930 | arraysize(data_reads)); |
| 931 | EXPECT_EQ(OK, out.rv); |
| 932 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 933 | EXPECT_EQ("Hello", out.response_data); |
| 934 | } |
| 935 | // 2 dupes and one mismatched. |
| 936 | { |
| 937 | MockRead data_reads[] = { |
| 938 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 939 | MockRead("Content-Length: 10\r\n"), |
| 940 | MockRead("Content-Length: 10\r\n"), |
| 941 | MockRead("Content-Length: 5\r\n\r\n"), |
| 942 | }; |
| 943 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 944 | arraysize(data_reads)); |
| 945 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 946 | } |
| 947 | } |
| 948 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 949 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 950 | MultipleContentLengthHeadersTransferEncoding) { |
| 951 | MockRead data_reads[] = { |
| 952 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 953 | MockRead("Content-Length: 666\r\n"), |
| 954 | MockRead("Content-Length: 1337\r\n"), |
| 955 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 956 | MockRead("5\r\nHello\r\n"), |
| 957 | MockRead("1\r\n"), |
| 958 | MockRead(" \r\n"), |
| 959 | MockRead("5\r\nworld\r\n"), |
| 960 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 961 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 962 | }; |
| 963 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 964 | arraysize(data_reads)); |
| 965 | EXPECT_EQ(OK, out.rv); |
| 966 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 967 | EXPECT_EQ("Hello world", out.response_data); |
| 968 | } |
| 969 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 970 | // Next tests deal with http://crbug.com/98895. |
| 971 | |
| 972 | // Checks that a single Content-Disposition header results in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 973 | TEST_P(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 974 | MockRead data_reads[] = { |
| 975 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 976 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 977 | MockRead("Content-Length: 5\r\n\r\n"), |
| 978 | MockRead("Hello"), |
| 979 | }; |
| 980 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 981 | arraysize(data_reads)); |
| 982 | EXPECT_EQ(OK, out.rv); |
| 983 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 984 | EXPECT_EQ("Hello", out.response_data); |
| 985 | } |
| 986 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 987 | // Checks that two identical Content-Disposition headers result in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 988 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 989 | TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 990 | MockRead data_reads[] = { |
| 991 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 992 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 993 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 994 | MockRead("Content-Length: 5\r\n\r\n"), |
| 995 | MockRead("Hello"), |
| 996 | }; |
| 997 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 998 | arraysize(data_reads)); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 999 | EXPECT_EQ(OK, out.rv); |
| 1000 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1001 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | // Checks that two distinct Content-Disposition headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1005 | TEST_P(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1006 | MockRead data_reads[] = { |
| 1007 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1008 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1009 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1010 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1011 | MockRead("Hello"), |
| 1012 | }; |
| 1013 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1014 | arraysize(data_reads)); |
| 1015 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION, out.rv); |
| 1016 | } |
| 1017 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1018 | // Checks that two identical Location headers result in no error. |
| 1019 | // Also tests Location header behavior. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1020 | TEST_P(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1021 | MockRead data_reads[] = { |
| 1022 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1023 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1024 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1025 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1026 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1027 | }; |
| 1028 | |
| 1029 | HttpRequestInfo request; |
| 1030 | request.method = "GET"; |
| 1031 | request.url = GURL("http://redirect.com/"); |
| 1032 | request.load_flags = 0; |
| 1033 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1034 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1035 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1036 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1037 | |
| 1038 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1039 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1040 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1041 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1042 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1043 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1044 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1045 | |
| 1046 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 1047 | |
| 1048 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1049 | ASSERT_TRUE(response != NULL && response->headers.get() != NULL); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1050 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1051 | std::string url; |
| 1052 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1053 | EXPECT_EQ("http://good.com/", url); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1054 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1055 | } |
| 1056 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1057 | // Checks that two distinct Location headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1058 | TEST_P(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1059 | MockRead data_reads[] = { |
| 1060 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1061 | MockRead("Location: http://good.com/\r\n"), |
| 1062 | MockRead("Location: http://evil.com/\r\n"), |
| 1063 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1064 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1065 | }; |
| 1066 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1067 | arraysize(data_reads)); |
| 1068 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION, out.rv); |
| 1069 | } |
| 1070 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1071 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1072 | // message body (since HEAD has none). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1073 | TEST_P(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1074 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1075 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1076 | request.url = GURL("http://www.example.org/"); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1077 | request.load_flags = 0; |
| 1078 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1079 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1080 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1081 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 1082 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 1083 | trans->SetBeforeProxyHeadersSentCallback( |
| 1084 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 1085 | base::Unretained(&proxy_headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1086 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1087 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1088 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1089 | "Host: www.example.org\r\n" |
| 1090 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1091 | }; |
| 1092 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1093 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1094 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1095 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1096 | // No response body because the test stops reading here. |
| 1097 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1098 | }; |
| 1099 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1100 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1101 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1102 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1103 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1104 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1105 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1106 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1107 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1108 | |
| 1109 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1110 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1111 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1112 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1113 | ASSERT_TRUE(response != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1114 | |
| 1115 | // Check that the headers got parsed. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1116 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1117 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1118 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1119 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 1120 | EXPECT_FALSE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1121 | |
| 1122 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1123 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1124 | bool has_server_header = response->headers->EnumerateHeader( |
| 1125 | &iter, "Server", &server_header); |
| 1126 | EXPECT_TRUE(has_server_header); |
| 1127 | EXPECT_EQ("Blah", server_header); |
| 1128 | |
| 1129 | // Reading should give EOF right away, since there is no message body |
| 1130 | // (despite non-zero content-length). |
| 1131 | std::string response_data; |
| 1132 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1133 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1134 | EXPECT_EQ("", response_data); |
| 1135 | } |
| 1136 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1137 | TEST_P(HttpNetworkTransactionTest, ReuseConnection) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1138 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1139 | |
| 1140 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1141 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1142 | MockRead("hello"), |
| 1143 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1144 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1145 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1146 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1147 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1148 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1149 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1150 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1151 | "hello", "world" |
| 1152 | }; |
| 1153 | |
| 1154 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1155 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1156 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1157 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1158 | request.load_flags = 0; |
| 1159 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1160 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1161 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1162 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1163 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1164 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1165 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1166 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1167 | |
| 1168 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1169 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1170 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1171 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1172 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1173 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1174 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1175 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1176 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1177 | |
| 1178 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1179 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1180 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1181 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1182 | } |
| 1183 | } |
| 1184 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1185 | TEST_P(HttpNetworkTransactionTest, Ignores100) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1186 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 1187 | element_readers.push_back( |
| 1188 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 1189 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1190 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1191 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1192 | request.method = "POST"; |
| 1193 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1194 | request.upload_data_stream = &upload_data_stream; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1195 | request.load_flags = 0; |
| 1196 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1197 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1198 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1199 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1200 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1201 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1202 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1203 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1204 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1205 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1206 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1207 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1208 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1209 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1210 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1211 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1212 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1213 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1214 | |
| 1215 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1216 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1217 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1218 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1219 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1220 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1221 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1222 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1223 | |
| 1224 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1225 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1226 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1227 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1228 | } |
| 1229 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1230 | // This test is almost the same as Ignores100 above, but the response contains |
| 1231 | // 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] | 1232 | // HTTP/1.1 and the two status headers are read in one read. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1233 | TEST_P(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1234 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1235 | request.method = "GET"; |
| 1236 | request.url = GURL("http://www.foo.com/"); |
| 1237 | request.load_flags = 0; |
| 1238 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1239 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1240 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1241 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1242 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1243 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1244 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1245 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1246 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1247 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1248 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1249 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1250 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1251 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1252 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1253 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1254 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1255 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1256 | |
| 1257 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1258 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1259 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1260 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1261 | ASSERT_TRUE(response != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1262 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1263 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1264 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1265 | |
| 1266 | std::string response_data; |
| 1267 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1268 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1269 | EXPECT_EQ("hello world", response_data); |
| 1270 | } |
| 1271 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1272 | TEST_P(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1273 | HttpRequestInfo request; |
| 1274 | request.method = "POST"; |
| 1275 | request.url = GURL("http://www.foo.com/"); |
| 1276 | request.load_flags = 0; |
| 1277 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1278 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1279 | scoped_ptr<HttpTransaction> trans( |
| 1280 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1281 | |
| 1282 | MockRead data_reads[] = { |
| 1283 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1284 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1285 | }; |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1286 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1287 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1288 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1289 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1290 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1291 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1292 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1293 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1294 | rv = callback.WaitForResult(); |
| 1295 | EXPECT_EQ(OK, rv); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1296 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1297 | std::string response_data; |
| 1298 | rv = ReadTransaction(trans.get(), &response_data); |
| 1299 | EXPECT_EQ(OK, rv); |
| 1300 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1301 | } |
| 1302 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1303 | TEST_P(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1304 | HttpRequestInfo request; |
| 1305 | request.method = "POST"; |
| 1306 | request.url = GURL("http://www.foo.com/"); |
| 1307 | request.load_flags = 0; |
| 1308 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1309 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1310 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1311 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1312 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1313 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1314 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1315 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1316 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1317 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1318 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1319 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1320 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1321 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1322 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1323 | |
| 1324 | rv = callback.WaitForResult(); |
| 1325 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
| 1326 | } |
| 1327 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1328 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1329 | const MockWrite* write_failure, |
| 1330 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1331 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1332 | request.method = "GET"; |
| 1333 | request.url = GURL("http://www.foo.com/"); |
| 1334 | request.load_flags = 0; |
| 1335 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1336 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1337 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1338 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1339 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1340 | // Written data for successfully sending both requests. |
| 1341 | MockWrite data1_writes[] = { |
| 1342 | MockWrite("GET / HTTP/1.1\r\n" |
| 1343 | "Host: www.foo.com\r\n" |
| 1344 | "Connection: keep-alive\r\n\r\n"), |
| 1345 | MockWrite("GET / HTTP/1.1\r\n" |
| 1346 | "Host: www.foo.com\r\n" |
| 1347 | "Connection: keep-alive\r\n\r\n") |
| 1348 | }; |
| 1349 | |
| 1350 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1351 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1352 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1353 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1354 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1355 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1356 | |
| 1357 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1358 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1359 | data1_writes[1] = *write_failure; |
| 1360 | } else { |
| 1361 | ASSERT_TRUE(read_failure); |
| 1362 | data1_reads[2] = *read_failure; |
| 1363 | } |
| 1364 | |
| 1365 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1366 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1367 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1368 | |
| 1369 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1370 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1371 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1372 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1373 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1374 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1375 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1376 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1377 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1378 | "hello", "world" |
| 1379 | }; |
| 1380 | |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 1381 | uint32_t first_socket_log_id = NetLog::Source::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1382 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1383 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1384 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1385 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1386 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1387 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1388 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1389 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1390 | |
| 1391 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1392 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1393 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1394 | LoadTimingInfo load_timing_info; |
| 1395 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1396 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1397 | if (i == 0) { |
| 1398 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1399 | } else { |
| 1400 | // The second request should be using a new socket. |
| 1401 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1402 | } |
| 1403 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1404 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1405 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1406 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1407 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1408 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1409 | |
| 1410 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1411 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1412 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1413 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1414 | } |
| 1415 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1416 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1417 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1418 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1419 | const MockRead* read_failure, |
| 1420 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1421 | HttpRequestInfo request; |
| 1422 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1423 | request.url = GURL("https://www.foo.com/"); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1424 | request.load_flags = 0; |
| 1425 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1426 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1427 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1428 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1429 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1430 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1431 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1432 | if (use_spdy) { |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 1433 | ssl1.SetNextProto(GetProtocol()); |
| 1434 | ssl2.SetNextProto(GetProtocol()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1435 | } |
| 1436 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1437 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1438 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1439 | // SPDY versions of the request and response. |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 1440 | scoped_ptr<SpdySerializedFrame> spdy_request(spdy_util_.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1441 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 1442 | scoped_ptr<SpdySerializedFrame> spdy_response( |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1443 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 1444 | scoped_ptr<SpdySerializedFrame> spdy_data( |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1445 | spdy_util_.ConstructSpdyBodyFrame(1, "hello", 5, true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1446 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1447 | // HTTP/1.1 versions of the request and response. |
| 1448 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1449 | "Host: www.foo.com\r\n" |
| 1450 | "Connection: keep-alive\r\n\r\n"; |
| 1451 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1452 | const char kHttpData[] = "hello"; |
| 1453 | |
| 1454 | std::vector<MockRead> data1_reads; |
| 1455 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1456 | if (write_failure) { |
| 1457 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1458 | data1_writes.push_back(*write_failure); |
| 1459 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1460 | } else { |
| 1461 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1462 | if (use_spdy) { |
| 1463 | data1_writes.push_back(CreateMockWrite(*spdy_request)); |
| 1464 | } else { |
| 1465 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1466 | } |
| 1467 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1468 | } |
| 1469 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1470 | StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(), |
| 1471 | &data1_writes[0], data1_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1472 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1473 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1474 | std::vector<MockRead> data2_reads; |
| 1475 | std::vector<MockWrite> data2_writes; |
| 1476 | |
| 1477 | if (use_spdy) { |
| 1478 | data2_writes.push_back(CreateMockWrite(*spdy_request, 0, ASYNC)); |
| 1479 | |
| 1480 | data2_reads.push_back(CreateMockRead(*spdy_response, 1, ASYNC)); |
| 1481 | data2_reads.push_back(CreateMockRead(*spdy_data, 2, ASYNC)); |
| 1482 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1483 | } else { |
| 1484 | data2_writes.push_back( |
| 1485 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1486 | |
| 1487 | data2_reads.push_back( |
| 1488 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1489 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1490 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1491 | } |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 1492 | SequencedSocketData data2(&data2_reads[0], data2_reads.size(), |
| 1493 | &data2_writes[0], data2_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1494 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1495 | |
| 1496 | // Preconnect a socket. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 1497 | SSLConfig ssl_config; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1498 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
bnc | 1f29537 | 2015-10-21 23:24:22 | [diff] [blame] | 1499 | session->GetAlpnProtos(&ssl_config.alpn_protos); |
| 1500 | session->GetNpnProtos(&ssl_config.npn_protos); |
mmenke | d1205bd | 2015-07-15 22:26:35 | [diff] [blame] | 1501 | session->http_stream_factory()->PreconnectStreams(1, request, ssl_config, |
| 1502 | ssl_config); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1503 | // Wait for the preconnect to complete. |
| 1504 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1505 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1506 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1507 | |
| 1508 | // Make the request. |
| 1509 | TestCompletionCallback callback; |
| 1510 | |
| 1511 | scoped_ptr<HttpTransaction> trans( |
| 1512 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1513 | |
| 1514 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1515 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1516 | |
| 1517 | rv = callback.WaitForResult(); |
| 1518 | EXPECT_EQ(OK, rv); |
| 1519 | |
| 1520 | LoadTimingInfo load_timing_info; |
| 1521 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1522 | TestLoadTimingNotReused( |
| 1523 | load_timing_info, |
| 1524 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1525 | |
| 1526 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1527 | ASSERT_TRUE(response != NULL); |
| 1528 | |
| 1529 | EXPECT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1530 | if (response->was_fetched_via_spdy) { |
| 1531 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1532 | } else { |
| 1533 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1534 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1535 | |
| 1536 | std::string response_data; |
| 1537 | rv = ReadTransaction(trans.get(), &response_data); |
| 1538 | EXPECT_EQ(OK, rv); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1539 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1540 | } |
| 1541 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1542 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 1543 | KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1544 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1545 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1546 | } |
| 1547 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1548 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1549 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1550 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1551 | } |
| 1552 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1553 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1554 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1555 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1556 | } |
| 1557 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1558 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1559 | // if the socket was a reused keep alive socket. |
| 1560 | TEST_P(HttpNetworkTransactionTest, KeepAlive408) { |
| 1561 | MockRead read_failure(SYNCHRONOUS, |
| 1562 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1563 | "Connection: Keep-Alive\r\n" |
| 1564 | "Content-Length: 6\r\n\r\n" |
| 1565 | "Pickle"); |
| 1566 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1567 | } |
| 1568 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1569 | TEST_P(HttpNetworkTransactionTest, |
| 1570 | PreconnectErrorNotConnectedOnWrite) { |
| 1571 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1572 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1573 | } |
| 1574 | |
| 1575 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorReset) { |
| 1576 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1577 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1578 | } |
| 1579 | |
| 1580 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
| 1581 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1582 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1583 | } |
| 1584 | |
| 1585 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
| 1586 | MockRead read_failure(ASYNC, OK); // EOF |
| 1587 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1588 | } |
| 1589 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1590 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1591 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
| 1592 | TEST_P(HttpNetworkTransactionTest, RetryOnIdle408) { |
| 1593 | MockRead read_failure(SYNCHRONOUS, |
| 1594 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1595 | "Connection: Keep-Alive\r\n" |
| 1596 | "Content-Length: 6\r\n\r\n" |
| 1597 | "Pickle"); |
| 1598 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1599 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1600 | } |
| 1601 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1602 | TEST_P(HttpNetworkTransactionTest, |
| 1603 | SpdyPreconnectErrorNotConnectedOnWrite) { |
| 1604 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1605 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1606 | } |
| 1607 | |
| 1608 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
| 1609 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1610 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1611 | } |
| 1612 | |
| 1613 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
| 1614 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1615 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1616 | } |
| 1617 | |
| 1618 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
| 1619 | MockRead read_failure(ASYNC, OK); // EOF |
| 1620 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1621 | } |
| 1622 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1623 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1624 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1625 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1626 | request.url = GURL("http://www.example.org/"); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1627 | request.load_flags = 0; |
| 1628 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1629 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1630 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1631 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1632 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1633 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1634 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1635 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1636 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1637 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1638 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1639 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1640 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1641 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1642 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1643 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1644 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1645 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1646 | |
| 1647 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1648 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1649 | |
| 1650 | IPEndPoint endpoint; |
| 1651 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 1652 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1653 | } |
| 1654 | |
| 1655 | // What do various browsers do when the server closes a non-keepalive |
| 1656 | // connection without sending any response header or body? |
| 1657 | // |
| 1658 | // IE7: error page |
| 1659 | // Safari 3.1.2 (Windows): error page |
| 1660 | // Firefox 3.0.1: blank page |
| 1661 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1662 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1663 | // Us: error page (EMPTY_RESPONSE) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1664 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1665 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1666 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1667 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1668 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1669 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1670 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1671 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1672 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1673 | EXPECT_EQ(ERR_EMPTY_RESPONSE, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1674 | } |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1675 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1676 | // Test that network access can be deferred and resumed. |
| 1677 | TEST_P(HttpNetworkTransactionTest, ThrottleBeforeNetworkStart) { |
| 1678 | HttpRequestInfo request; |
| 1679 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1680 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1681 | request.load_flags = 0; |
| 1682 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1683 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1684 | scoped_ptr<HttpTransaction> trans( |
| 1685 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1686 | |
| 1687 | // Defer on OnBeforeNetworkStart. |
| 1688 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1689 | trans->SetBeforeNetworkStartCallback( |
| 1690 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1691 | base::Unretained(&net_start_handler))); |
| 1692 | |
| 1693 | MockRead data_reads[] = { |
| 1694 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1695 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1696 | MockRead("hello"), |
| 1697 | MockRead(SYNCHRONOUS, 0), |
| 1698 | }; |
| 1699 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1700 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1701 | |
| 1702 | TestCompletionCallback callback; |
| 1703 | |
| 1704 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1705 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1706 | base::MessageLoop::current()->RunUntilIdle(); |
| 1707 | |
| 1708 | // Should have deferred for network start. |
| 1709 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1710 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1711 | |
| 1712 | trans->ResumeNetworkStart(); |
| 1713 | rv = callback.WaitForResult(); |
| 1714 | EXPECT_EQ(OK, rv); |
| 1715 | EXPECT_TRUE(trans->GetResponseInfo() != NULL); |
| 1716 | |
| 1717 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
| 1718 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
| 1719 | if (rv == ERR_IO_PENDING) |
| 1720 | rv = callback.WaitForResult(); |
| 1721 | EXPECT_EQ(5, rv); |
| 1722 | trans.reset(); |
| 1723 | } |
| 1724 | |
| 1725 | // Test that network use can be deferred and canceled. |
| 1726 | TEST_P(HttpNetworkTransactionTest, ThrottleAndCancelBeforeNetworkStart) { |
| 1727 | HttpRequestInfo request; |
| 1728 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1729 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1730 | request.load_flags = 0; |
| 1731 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1732 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1733 | scoped_ptr<HttpTransaction> trans( |
| 1734 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1735 | |
| 1736 | // Defer on OnBeforeNetworkStart. |
| 1737 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1738 | trans->SetBeforeNetworkStartCallback( |
| 1739 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1740 | base::Unretained(&net_start_handler))); |
| 1741 | |
| 1742 | TestCompletionCallback callback; |
| 1743 | |
| 1744 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1745 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1746 | base::MessageLoop::current()->RunUntilIdle(); |
| 1747 | |
| 1748 | // Should have deferred for network start. |
| 1749 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1750 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1751 | } |
| 1752 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1753 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1754 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1755 | // destructor in such situations. |
| 1756 | // See http://crbug.com/154712 and http://crbug.com/156609. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1757 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1758 | HttpRequestInfo request; |
| 1759 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1760 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1761 | request.load_flags = 0; |
| 1762 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1763 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1764 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1765 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1766 | |
| 1767 | MockRead data_reads[] = { |
| 1768 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1769 | MockRead("Connection: keep-alive\r\n"), |
| 1770 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1771 | MockRead("hello"), |
| 1772 | MockRead(SYNCHRONOUS, 0), |
| 1773 | }; |
| 1774 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1775 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1776 | |
| 1777 | TestCompletionCallback callback; |
| 1778 | |
| 1779 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1780 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1781 | |
| 1782 | rv = callback.WaitForResult(); |
| 1783 | EXPECT_EQ(OK, rv); |
| 1784 | |
| 1785 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1786 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1787 | if (rv == ERR_IO_PENDING) |
| 1788 | rv = callback.WaitForResult(); |
| 1789 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1790 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1791 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1792 | |
| 1793 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1794 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1795 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1796 | } |
| 1797 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1798 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1799 | HttpRequestInfo request; |
| 1800 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1801 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1802 | request.load_flags = 0; |
| 1803 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1804 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1805 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1806 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1807 | |
| 1808 | MockRead data_reads[] = { |
| 1809 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1810 | MockRead("Connection: keep-alive\r\n"), |
| 1811 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1812 | MockRead(SYNCHRONOUS, 0), |
| 1813 | }; |
| 1814 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1815 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1816 | |
| 1817 | TestCompletionCallback callback; |
| 1818 | |
| 1819 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1820 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1821 | |
| 1822 | rv = callback.WaitForResult(); |
| 1823 | EXPECT_EQ(OK, rv); |
| 1824 | |
| 1825 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1826 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1827 | if (rv == ERR_IO_PENDING) |
| 1828 | rv = callback.WaitForResult(); |
| 1829 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1830 | |
| 1831 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1832 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1833 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1834 | } |
| 1835 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1836 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1837 | // reading the body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1838 | TEST_P(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1839 | HttpRequestInfo request; |
| 1840 | request.method = "GET"; |
| 1841 | request.url = GURL("http://www.foo.com/"); |
| 1842 | request.load_flags = 0; |
| 1843 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1844 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1845 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1846 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1847 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1848 | const char* request_data = |
| 1849 | "GET / HTTP/1.1\r\n" |
| 1850 | "Host: www.foo.com\r\n" |
| 1851 | "Connection: keep-alive\r\n\r\n"; |
| 1852 | MockWrite data_writes[] = { |
| 1853 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 1854 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 1855 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 1856 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 1857 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 1858 | }; |
| 1859 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1860 | // Note that because all these reads happen in the same |
| 1861 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 1862 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1863 | MockRead data_reads[] = { |
| 1864 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 1865 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 1866 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 1867 | MockRead(ASYNC, 7, |
| 1868 | "HTTP/1.1 302 Found\r\n" |
| 1869 | "Content-Length: 0\r\n\r\n"), |
| 1870 | MockRead(ASYNC, 9, |
| 1871 | "HTTP/1.1 302 Found\r\n" |
| 1872 | "Content-Length: 5\r\n\r\n" |
| 1873 | "hello"), |
| 1874 | MockRead(ASYNC, 11, |
| 1875 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 1876 | "Content-Length: 0\r\n\r\n"), |
| 1877 | MockRead(ASYNC, 13, |
| 1878 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 1879 | "Content-Length: 5\r\n\r\n" |
| 1880 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1881 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1882 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 1883 | // the set_busy_before_sync_reads(true) call, while the |
| 1884 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 1885 | // reuseable. See http://crbug.com/544255. |
| 1886 | MockRead(ASYNC, 15, |
| 1887 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 1888 | "Content-Length: 5\r\n\r\n"), |
| 1889 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1890 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1891 | MockRead(ASYNC, 18, |
| 1892 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 1893 | "Content-Length: 5\r\n\r\n" |
| 1894 | "he"), |
| 1895 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 1896 | |
| 1897 | // The body of the final request is actually read. |
| 1898 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1899 | MockRead(ASYNC, 22, "hello"), |
| 1900 | }; |
| 1901 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 1902 | arraysize(data_writes)); |
| 1903 | data.set_busy_before_sync_reads(true); |
| 1904 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1905 | |
| 1906 | const int kNumUnreadBodies = arraysize(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1907 | std::string response_lines[kNumUnreadBodies]; |
| 1908 | |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 1909 | uint32_t first_socket_log_id = NetLog::Source::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1910 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1911 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1912 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1913 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1914 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1915 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1916 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1917 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1918 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1919 | LoadTimingInfo load_timing_info; |
| 1920 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1921 | if (i == 0) { |
| 1922 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1923 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1924 | } else { |
| 1925 | TestLoadTimingReused(load_timing_info); |
| 1926 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 1927 | } |
| 1928 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1929 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1930 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1931 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1932 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1933 | response_lines[i] = response->headers->GetStatusLine(); |
| 1934 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1935 | // Delete the transaction without reading the response bodies. Then spin |
| 1936 | // the message loop, so the response bodies are drained. |
| 1937 | trans.reset(); |
| 1938 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1939 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1940 | |
| 1941 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1942 | "HTTP/1.1 204 No Content", |
| 1943 | "HTTP/1.1 205 Reset Content", |
| 1944 | "HTTP/1.1 304 Not Modified", |
| 1945 | "HTTP/1.1 302 Found", |
| 1946 | "HTTP/1.1 302 Found", |
| 1947 | "HTTP/1.1 301 Moved Permanently", |
| 1948 | "HTTP/1.1 301 Moved Permanently", |
| 1949 | "HTTP/1.1 200 Hunky-Dory", |
| 1950 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1951 | }; |
| 1952 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 1953 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 1954 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1955 | |
| 1956 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 1957 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 1958 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1959 | TestCompletionCallback callback; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1960 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1961 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1962 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1963 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1964 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1965 | ASSERT_TRUE(response); |
| 1966 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1967 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1968 | std::string response_data; |
| 1969 | rv = ReadTransaction(trans.get(), &response_data); |
| 1970 | EXPECT_EQ(OK, rv); |
| 1971 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1972 | } |
| 1973 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1974 | // Test the request-challenge-retry sequence for basic auth. |
| 1975 | // (basic auth is the easiest to mock, because it has no randomness). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1976 | TEST_P(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1977 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1978 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1979 | request.url = GURL("http://www.example.org/"); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1980 | request.load_flags = 0; |
| 1981 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1982 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1983 | session_deps_.net_log = &log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1984 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1985 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1986 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1987 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1988 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1989 | MockWrite( |
| 1990 | "GET / HTTP/1.1\r\n" |
| 1991 | "Host: www.example.org\r\n" |
| 1992 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1993 | }; |
| 1994 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1995 | MockRead data_reads1[] = { |
| 1996 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 1997 | // Give a couple authenticate options (only the middle one is actually |
| 1998 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 1999 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2000 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2001 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2002 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2003 | // Large content-length -- won't matter, as connection will be reset. |
| 2004 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2005 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2006 | }; |
| 2007 | |
| 2008 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2009 | // be issuing -- the final header line contains the credentials. |
| 2010 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2011 | MockWrite( |
| 2012 | "GET / HTTP/1.1\r\n" |
| 2013 | "Host: www.example.org\r\n" |
| 2014 | "Connection: keep-alive\r\n" |
| 2015 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2016 | }; |
| 2017 | |
| 2018 | // Lastly, the server responds with the actual content. |
| 2019 | MockRead data_reads2[] = { |
| 2020 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2021 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2022 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2023 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2024 | }; |
| 2025 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2026 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2027 | data_writes1, arraysize(data_writes1)); |
| 2028 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2029 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2030 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2031 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2032 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2033 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2034 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2035 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2036 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2037 | |
| 2038 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2039 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2040 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2041 | LoadTimingInfo load_timing_info1; |
| 2042 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2043 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2044 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2045 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
| 2046 | EXPECT_EQ(writes_size1, trans->GetTotalSentBytes()); |
| 2047 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2048 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
| 2049 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2050 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2051 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2052 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2053 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2054 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2055 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2056 | rv = trans->RestartWithAuth( |
| 2057 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2058 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2059 | |
| 2060 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2061 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2062 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2063 | LoadTimingInfo load_timing_info2; |
| 2064 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2065 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2066 | // The load timing after restart should have a new socket ID, and times after |
| 2067 | // those of the first load timing. |
| 2068 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2069 | load_timing_info2.connect_timing.connect_start); |
| 2070 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2071 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2072 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
| 2073 | EXPECT_EQ(writes_size1 + writes_size2, trans->GetTotalSentBytes()); |
| 2074 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2075 | EXPECT_EQ(reads_size1 + reads_size2, trans->GetTotalReceivedBytes()); |
| 2076 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2077 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2078 | ASSERT_TRUE(response != NULL); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2079 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2080 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2081 | } |
| 2082 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2083 | // Test the request-challenge-retry sequence for basic auth. |
| 2084 | // (basic auth is the easiest to mock, because it has no randomness). |
| 2085 | TEST_P(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
| 2086 | HttpRequestInfo request; |
| 2087 | request.method = "GET"; |
| 2088 | request.url = GURL("http://www.example.org/"); |
| 2089 | request.load_flags = 0; |
| 2090 | |
| 2091 | TestNetLog log; |
| 2092 | MockHostResolver* resolver = new MockHostResolver(); |
| 2093 | session_deps_.net_log = &log; |
| 2094 | session_deps_.host_resolver.reset(resolver); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2095 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2096 | scoped_ptr<HttpTransaction> trans( |
| 2097 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2098 | |
| 2099 | resolver->rules()->ClearRules(); |
| 2100 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2101 | |
| 2102 | MockWrite data_writes1[] = { |
| 2103 | MockWrite("GET / HTTP/1.1\r\n" |
| 2104 | "Host: www.example.org\r\n" |
| 2105 | "Connection: keep-alive\r\n\r\n"), |
| 2106 | }; |
| 2107 | |
| 2108 | MockRead data_reads1[] = { |
| 2109 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2110 | // Give a couple authenticate options (only the middle one is actually |
| 2111 | // supported). |
| 2112 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2113 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2114 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2115 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2116 | // Large content-length -- won't matter, as connection will be reset. |
| 2117 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2118 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2119 | }; |
| 2120 | |
| 2121 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2122 | // be issuing -- the final header line contains the credentials. |
| 2123 | MockWrite data_writes2[] = { |
| 2124 | MockWrite("GET / HTTP/1.1\r\n" |
| 2125 | "Host: www.example.org\r\n" |
| 2126 | "Connection: keep-alive\r\n" |
| 2127 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2128 | }; |
| 2129 | |
| 2130 | // Lastly, the server responds with the actual content. |
| 2131 | MockRead data_reads2[] = { |
| 2132 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2133 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2134 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2135 | }; |
| 2136 | |
| 2137 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2138 | data_writes1, arraysize(data_writes1)); |
| 2139 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2140 | data_writes2, arraysize(data_writes2)); |
| 2141 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2142 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2143 | |
| 2144 | TestCompletionCallback callback1; |
| 2145 | |
| 2146 | EXPECT_EQ(OK, callback1.GetResult(trans->Start(&request, callback1.callback(), |
| 2147 | BoundNetLog()))); |
| 2148 | |
| 2149 | LoadTimingInfo load_timing_info1; |
| 2150 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2151 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2152 | |
| 2153 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
| 2154 | EXPECT_EQ(writes_size1, trans->GetTotalSentBytes()); |
| 2155 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
| 2156 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
| 2157 | |
| 2158 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2159 | ASSERT_TRUE(response); |
| 2160 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2161 | |
| 2162 | IPEndPoint endpoint; |
| 2163 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 2164 | ASSERT_FALSE(endpoint.address().empty()); |
| 2165 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2166 | |
| 2167 | resolver->rules()->ClearRules(); |
| 2168 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2169 | |
| 2170 | TestCompletionCallback callback2; |
| 2171 | |
| 2172 | EXPECT_EQ(OK, callback2.GetResult(trans->RestartWithAuth( |
| 2173 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2174 | |
| 2175 | LoadTimingInfo load_timing_info2; |
| 2176 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2177 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2178 | // The load timing after restart should have a new socket ID, and times after |
| 2179 | // those of the first load timing. |
| 2180 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2181 | load_timing_info2.connect_timing.connect_start); |
| 2182 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2183 | |
| 2184 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
| 2185 | EXPECT_EQ(writes_size1 + writes_size2, trans->GetTotalSentBytes()); |
| 2186 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
| 2187 | EXPECT_EQ(reads_size1 + reads_size2, trans->GetTotalReceivedBytes()); |
| 2188 | |
| 2189 | response = trans->GetResponseInfo(); |
| 2190 | ASSERT_TRUE(response); |
| 2191 | EXPECT_FALSE(response->auth_challenge.get()); |
| 2192 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2193 | |
| 2194 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 2195 | ASSERT_FALSE(endpoint.address().empty()); |
| 2196 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2197 | } |
| 2198 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2199 | TEST_P(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2200 | HttpRequestInfo request; |
| 2201 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2202 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2203 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2204 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2205 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2206 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 2207 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2208 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2209 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2210 | MockWrite( |
| 2211 | "GET / HTTP/1.1\r\n" |
| 2212 | "Host: www.example.org\r\n" |
| 2213 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2214 | }; |
| 2215 | |
| 2216 | MockRead data_reads[] = { |
| 2217 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2218 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2219 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2220 | // Large content-length -- won't matter, as connection will be reset. |
| 2221 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2222 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2223 | }; |
| 2224 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2225 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2226 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2227 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2228 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2229 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2230 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2231 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2232 | |
| 2233 | rv = callback.WaitForResult(); |
| 2234 | EXPECT_EQ(0, rv); |
| 2235 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2236 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
| 2237 | EXPECT_EQ(writes_size, trans->GetTotalSentBytes()); |
| 2238 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2239 | EXPECT_EQ(reads_size, trans->GetTotalReceivedBytes()); |
| 2240 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2241 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2242 | ASSERT_TRUE(response != NULL); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2243 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2244 | } |
| 2245 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2246 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2247 | // connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2248 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2249 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2250 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2251 | // reused. See http://crbug.com/544255. |
| 2252 | for (int i = 0; i < 2; ++i) { |
| 2253 | HttpRequestInfo request; |
| 2254 | request.method = "GET"; |
| 2255 | request.url = GURL("http://www.example.org/"); |
| 2256 | request.load_flags = 0; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2257 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2258 | TestNetLog log; |
| 2259 | session_deps_.net_log = &log; |
| 2260 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2261 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2262 | MockWrite data_writes[] = { |
| 2263 | MockWrite(ASYNC, 0, |
| 2264 | "GET / HTTP/1.1\r\n" |
| 2265 | "Host: www.example.org\r\n" |
| 2266 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2267 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2268 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2269 | // be issuing -- the final header line contains the credentials. |
| 2270 | MockWrite(ASYNC, 6, |
| 2271 | "GET / HTTP/1.1\r\n" |
| 2272 | "Host: www.example.org\r\n" |
| 2273 | "Connection: keep-alive\r\n" |
| 2274 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2275 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2276 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2277 | MockRead data_reads[] = { |
| 2278 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2279 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2280 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2281 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2282 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2283 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2284 | // Lastly, the server responds with the actual content. |
| 2285 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2286 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2287 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2288 | MockRead(ASYNC, 10, "Hello"), |
| 2289 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2290 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2291 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 2292 | arraysize(data_writes)); |
| 2293 | data.set_busy_before_sync_reads(true); |
| 2294 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2295 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2296 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2297 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2298 | scoped_ptr<HttpTransaction> trans( |
| 2299 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2300 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 2301 | ASSERT_EQ(OK, callback1.GetResult(rv)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2302 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2303 | LoadTimingInfo load_timing_info1; |
| 2304 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2305 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2306 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2307 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2308 | ASSERT_TRUE(response); |
| 2309 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2310 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2311 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2312 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2313 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2314 | callback2.callback()); |
| 2315 | ASSERT_EQ(OK, callback2.GetResult(rv)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2316 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2317 | LoadTimingInfo load_timing_info2; |
| 2318 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2319 | TestLoadTimingReused(load_timing_info2); |
| 2320 | // The load timing after restart should have the same socket ID, and times |
| 2321 | // those of the first load timing. |
| 2322 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2323 | load_timing_info2.send_start); |
| 2324 | 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] | 2325 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2326 | response = trans->GetResponseInfo(); |
| 2327 | ASSERT_TRUE(response); |
| 2328 | EXPECT_FALSE(response->auth_challenge); |
| 2329 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2330 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2331 | std::string response_data; |
| 2332 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2333 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2334 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
| 2335 | EXPECT_EQ(writes_size, trans->GetTotalSentBytes()); |
| 2336 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 2337 | EXPECT_EQ(reads_size, trans->GetTotalReceivedBytes()); |
| 2338 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2339 | } |
| 2340 | |
| 2341 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2342 | // connection and with no response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2343 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2344 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2345 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2346 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2347 | request.load_flags = 0; |
| 2348 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2349 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2350 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2351 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2352 | MockWrite( |
| 2353 | "GET / HTTP/1.1\r\n" |
| 2354 | "Host: www.example.org\r\n" |
| 2355 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2356 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2357 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2358 | // be issuing -- the final header line contains the credentials. |
| 2359 | MockWrite( |
| 2360 | "GET / HTTP/1.1\r\n" |
| 2361 | "Host: www.example.org\r\n" |
| 2362 | "Connection: keep-alive\r\n" |
| 2363 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2364 | }; |
| 2365 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2366 | MockRead data_reads1[] = { |
| 2367 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2368 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2369 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2370 | |
| 2371 | // Lastly, the server responds with the actual content. |
| 2372 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2373 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2374 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2375 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2376 | }; |
| 2377 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2378 | // An incorrect reconnect would cause this to be read. |
| 2379 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2380 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2381 | }; |
| 2382 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2383 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2384 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2385 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2386 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2387 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2388 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2389 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2390 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2391 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2392 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2393 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2394 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2395 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2396 | |
| 2397 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2398 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2399 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2400 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2401 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2402 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2403 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2404 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2405 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2406 | rv = trans->RestartWithAuth( |
| 2407 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2408 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2409 | |
| 2410 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2411 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2412 | |
| 2413 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2414 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2415 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2416 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2417 | } |
| 2418 | |
| 2419 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2420 | // connection and with a large response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2421 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2422 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2423 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2424 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2425 | request.load_flags = 0; |
| 2426 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2427 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2428 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2429 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2430 | MockWrite( |
| 2431 | "GET / HTTP/1.1\r\n" |
| 2432 | "Host: www.example.org\r\n" |
| 2433 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2434 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2435 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2436 | // be issuing -- the final header line contains the credentials. |
| 2437 | MockWrite( |
| 2438 | "GET / HTTP/1.1\r\n" |
| 2439 | "Host: www.example.org\r\n" |
| 2440 | "Connection: keep-alive\r\n" |
| 2441 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2442 | }; |
| 2443 | |
| 2444 | // Respond with 5 kb of response body. |
| 2445 | std::string large_body_string("Unauthorized"); |
| 2446 | large_body_string.append(5 * 1024, ' '); |
| 2447 | large_body_string.append("\r\n"); |
| 2448 | |
| 2449 | MockRead data_reads1[] = { |
| 2450 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2451 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2452 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2453 | // 5134 = 12 + 5 * 1024 + 2 |
| 2454 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2455 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2456 | |
| 2457 | // Lastly, the server responds with the actual content. |
| 2458 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2459 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2460 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2461 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2462 | }; |
| 2463 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2464 | // An incorrect reconnect would cause this to be read. |
| 2465 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2466 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2467 | }; |
| 2468 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2469 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2470 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2471 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2472 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2473 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2474 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2475 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2476 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2477 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2478 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2479 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2480 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2481 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2482 | |
| 2483 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2484 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2485 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2486 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2487 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2488 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2489 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2490 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2491 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2492 | rv = trans->RestartWithAuth( |
| 2493 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2494 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2495 | |
| 2496 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2497 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2498 | |
| 2499 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2500 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2501 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2502 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2503 | } |
| 2504 | |
| 2505 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2506 | // connection, but the server gets impatient and closes the connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2507 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2508 | HttpRequestInfo request; |
| 2509 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2510 | request.url = GURL("http://www.example.org/"); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2511 | request.load_flags = 0; |
| 2512 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2513 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2514 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2515 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2516 | MockWrite( |
| 2517 | "GET / HTTP/1.1\r\n" |
| 2518 | "Host: www.example.org\r\n" |
| 2519 | "Connection: keep-alive\r\n\r\n"), |
| 2520 | // This simulates the seemingly successful write to a closed connection |
| 2521 | // if the bug is not fixed. |
| 2522 | MockWrite( |
| 2523 | "GET / HTTP/1.1\r\n" |
| 2524 | "Host: www.example.org\r\n" |
| 2525 | "Connection: keep-alive\r\n" |
| 2526 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2527 | }; |
| 2528 | |
| 2529 | MockRead data_reads1[] = { |
| 2530 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2531 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2532 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2533 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2534 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2535 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2536 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2537 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2538 | }; |
| 2539 | |
| 2540 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2541 | // be issuing -- the final header line contains the credentials. |
| 2542 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2543 | MockWrite( |
| 2544 | "GET / HTTP/1.1\r\n" |
| 2545 | "Host: www.example.org\r\n" |
| 2546 | "Connection: keep-alive\r\n" |
| 2547 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2548 | }; |
| 2549 | |
| 2550 | // Lastly, the server responds with the actual content. |
| 2551 | MockRead data_reads2[] = { |
| 2552 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2553 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2554 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2555 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2556 | }; |
| 2557 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2558 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2559 | data_writes1, arraysize(data_writes1)); |
| 2560 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2561 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2562 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2563 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2564 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2565 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2566 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2567 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2568 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2569 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2570 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2571 | |
| 2572 | rv = callback1.WaitForResult(); |
| 2573 | EXPECT_EQ(OK, rv); |
| 2574 | |
| 2575 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2576 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2577 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2578 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2579 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2580 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2581 | rv = trans->RestartWithAuth( |
| 2582 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2583 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2584 | |
| 2585 | rv = callback2.WaitForResult(); |
| 2586 | EXPECT_EQ(OK, rv); |
| 2587 | |
| 2588 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2589 | ASSERT_TRUE(response != NULL); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2590 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2591 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2592 | } |
| 2593 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2594 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2595 | // that requires a restart when setting up an SSL tunnel. |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2596 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
| 2597 | HttpRequestInfo request; |
| 2598 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2599 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2600 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2601 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2602 | |
| 2603 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2604 | session_deps_.proxy_service = |
| 2605 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2606 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2607 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2608 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2609 | |
| 2610 | // Since we have proxy, should try to establish tunnel. |
| 2611 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2612 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2613 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2614 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2615 | }; |
| 2616 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2617 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2618 | // connection. |
| 2619 | MockRead data_reads1[] = { |
| 2620 | // No credentials. |
| 2621 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2622 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2623 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2624 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2625 | // Since the first connection couldn't be reused, need to establish another |
| 2626 | // once given credentials. |
| 2627 | MockWrite data_writes2[] = { |
| 2628 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2629 | // be issuing -- the final header line contains the credentials. |
| 2630 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2631 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2632 | "Proxy-Connection: keep-alive\r\n" |
| 2633 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2634 | |
| 2635 | MockWrite("GET / HTTP/1.1\r\n" |
| 2636 | "Host: www.example.org\r\n" |
| 2637 | "Connection: keep-alive\r\n\r\n"), |
| 2638 | }; |
| 2639 | |
| 2640 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2641 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 2642 | |
| 2643 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2644 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2645 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2646 | MockRead(SYNCHRONOUS, "hello"), |
| 2647 | }; |
| 2648 | |
| 2649 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2650 | data_writes1, arraysize(data_writes1)); |
| 2651 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2652 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2653 | data_writes2, arraysize(data_writes2)); |
| 2654 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2655 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 2656 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 2657 | |
| 2658 | TestCompletionCallback callback1; |
| 2659 | |
| 2660 | scoped_ptr<HttpTransaction> trans( |
| 2661 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2662 | |
| 2663 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 2664 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2665 | |
| 2666 | rv = callback1.WaitForResult(); |
| 2667 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2668 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2669 | log.GetEntries(&entries); |
| 2670 | size_t pos = ExpectLogContainsSomewhere( |
| 2671 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2672 | NetLog::PHASE_NONE); |
| 2673 | ExpectLogContainsSomewhere( |
| 2674 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2675 | NetLog::PHASE_NONE); |
| 2676 | |
| 2677 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2678 | ASSERT_TRUE(response != NULL); |
| 2679 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 2680 | ASSERT_FALSE(response->headers.get() == NULL); |
| 2681 | EXPECT_EQ(407, response->headers->response_code()); |
| 2682 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2683 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2684 | |
| 2685 | LoadTimingInfo load_timing_info; |
| 2686 | // CONNECT requests and responses are handled at the connect job level, so |
| 2687 | // the transaction does not yet have a connection. |
| 2688 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2689 | |
| 2690 | TestCompletionCallback callback2; |
| 2691 | |
| 2692 | rv = |
| 2693 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 2694 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2695 | |
| 2696 | rv = callback2.WaitForResult(); |
| 2697 | EXPECT_EQ(OK, rv); |
| 2698 | |
| 2699 | response = trans->GetResponseInfo(); |
| 2700 | ASSERT_TRUE(response != NULL); |
| 2701 | |
| 2702 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2703 | EXPECT_EQ(200, response->headers->response_code()); |
| 2704 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 2705 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2706 | |
| 2707 | // The password prompt info should not be set. |
| 2708 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2709 | |
| 2710 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2711 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2712 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2713 | |
| 2714 | trans.reset(); |
| 2715 | session->CloseAllConnections(); |
| 2716 | } |
| 2717 | |
| 2718 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2719 | // that requires a restart when setting up an SSL tunnel. |
| 2720 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2721 | HttpRequestInfo request; |
| 2722 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2723 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2724 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2725 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2726 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2727 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2728 | session_deps_.proxy_service = |
| 2729 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2730 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2731 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2732 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2733 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2734 | // Since we have proxy, should try to establish tunnel. |
| 2735 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2736 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2737 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2738 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2739 | }; |
| 2740 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2741 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 2742 | // connection. |
| 2743 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2744 | // No credentials. |
| 2745 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2746 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2747 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 2748 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2749 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2750 | MockWrite data_writes2[] = { |
| 2751 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2752 | // be issuing -- the final header line contains the credentials. |
| 2753 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2754 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2755 | "Proxy-Connection: keep-alive\r\n" |
| 2756 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 2757 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2758 | MockWrite("GET / HTTP/1.1\r\n" |
| 2759 | "Host: www.example.org\r\n" |
| 2760 | "Connection: keep-alive\r\n\r\n"), |
| 2761 | }; |
| 2762 | |
| 2763 | MockRead data_reads2[] = { |
| 2764 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2765 | |
| 2766 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2767 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2768 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2769 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2770 | }; |
| 2771 | |
| 2772 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2773 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2774 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2775 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2776 | data_writes2, arraysize(data_writes2)); |
| 2777 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2778 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2779 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2780 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2781 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2782 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2783 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2784 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2785 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2786 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2787 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2788 | |
| 2789 | rv = callback1.WaitForResult(); |
| 2790 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2791 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2792 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2793 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2794 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2795 | NetLog::PHASE_NONE); |
| 2796 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2797 | entries, pos, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2798 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2799 | NetLog::PHASE_NONE); |
| 2800 | |
| 2801 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2802 | ASSERT_TRUE(response != NULL); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2803 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2804 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2805 | EXPECT_EQ(407, response->headers->response_code()); |
| 2806 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2807 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2808 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2809 | LoadTimingInfo load_timing_info; |
| 2810 | // CONNECT requests and responses are handled at the connect job level, so |
| 2811 | // the transaction does not yet have a connection. |
| 2812 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2813 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2814 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2815 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2816 | rv = trans->RestartWithAuth( |
| 2817 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2818 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2819 | |
| 2820 | rv = callback2.WaitForResult(); |
| 2821 | EXPECT_EQ(OK, rv); |
| 2822 | |
| 2823 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2824 | ASSERT_TRUE(response != NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2825 | |
| 2826 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2827 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2828 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2829 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2830 | |
| 2831 | // The password prompt info should not be set. |
| 2832 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2833 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2834 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2835 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2836 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2837 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2838 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2839 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2840 | } |
| 2841 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2842 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2843 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
| 2844 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 2845 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2846 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2847 | // reused. See http://crbug.com/544255. |
| 2848 | for (int i = 0; i < 2; ++i) { |
| 2849 | HttpRequestInfo request; |
| 2850 | request.method = "GET"; |
| 2851 | request.url = GURL("https://www.example.org/"); |
| 2852 | // Ensure that proxy authentication is attempted even |
| 2853 | // when the no authentication data flag is set. |
| 2854 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2855 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 2856 | // Configure against proxy server "myproxy:70". |
| 2857 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 2858 | BoundTestNetLog log; |
| 2859 | session_deps_.net_log = log.bound().net_log(); |
| 2860 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2861 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 2862 | scoped_ptr<HttpTransaction> trans( |
| 2863 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2864 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 2865 | // Since we have proxy, should try to establish tunnel. |
| 2866 | MockWrite data_writes1[] = { |
| 2867 | MockWrite(ASYNC, 0, |
| 2868 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2869 | "Host: www.example.org:443\r\n" |
| 2870 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2871 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 2872 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2873 | // be issuing -- the final header line contains the credentials. |
| 2874 | MockWrite(ASYNC, 3, |
| 2875 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2876 | "Host: www.example.org:443\r\n" |
| 2877 | "Proxy-Connection: keep-alive\r\n" |
| 2878 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 2879 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2880 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 2881 | // The proxy responds to the connect with a 407, using a persistent |
| 2882 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 2883 | MockRead data_reads1[] = { |
| 2884 | // No credentials. |
| 2885 | MockRead(ASYNC, 1, |
| 2886 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 2887 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 2888 | "Proxy-Connection: keep-alive\r\n" |
| 2889 | "Content-Length: 10\r\n\r\n"), |
| 2890 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2891 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 2892 | // Wrong credentials (wrong password). |
| 2893 | MockRead(ASYNC, 4, |
| 2894 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 2895 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 2896 | "Proxy-Connection: keep-alive\r\n" |
| 2897 | "Content-Length: 10\r\n\r\n"), |
| 2898 | // No response body because the test stops reading here. |
| 2899 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 2900 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2901 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 2902 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 2903 | arraysize(data_writes1)); |
| 2904 | data1.set_busy_before_sync_reads(true); |
| 2905 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2906 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 2907 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2908 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 2909 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 2910 | EXPECT_EQ(OK, callback1.GetResult(rv)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2911 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 2912 | TestNetLogEntry::List entries; |
| 2913 | log.GetEntries(&entries); |
| 2914 | size_t pos = ExpectLogContainsSomewhere( |
| 2915 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2916 | NetLog::PHASE_NONE); |
| 2917 | ExpectLogContainsSomewhere( |
| 2918 | entries, pos, |
| 2919 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2920 | NetLog::PHASE_NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2921 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 2922 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2923 | ASSERT_TRUE(response); |
| 2924 | ASSERT_TRUE(response->headers); |
| 2925 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2926 | EXPECT_EQ(407, response->headers->response_code()); |
| 2927 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 2928 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2929 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2930 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 2931 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2932 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 2933 | // Wrong password (should be "bar"). |
| 2934 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 2935 | callback2.callback()); |
| 2936 | EXPECT_EQ(OK, callback2.GetResult(rv)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2937 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 2938 | response = trans->GetResponseInfo(); |
| 2939 | ASSERT_TRUE(response); |
| 2940 | ASSERT_TRUE(response->headers); |
| 2941 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2942 | EXPECT_EQ(407, response->headers->response_code()); |
| 2943 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 2944 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2945 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2946 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 2947 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 2948 | // out of scope. |
| 2949 | session->CloseAllConnections(); |
| 2950 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2951 | } |
| 2952 | |
| 2953 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2954 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
| 2955 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 2956 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2957 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2958 | // reused. See http://crbug.com/544255. |
| 2959 | for (int i = 0; i < 2; ++i) { |
| 2960 | HttpRequestInfo request; |
| 2961 | request.method = "GET"; |
| 2962 | request.url = GURL("https://www.example.org/"); |
| 2963 | // Ensure that proxy authentication is attempted even |
| 2964 | // when the no authentication data flag is set. |
| 2965 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 2966 | |
| 2967 | // Configure against proxy server "myproxy:70". |
| 2968 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 2969 | BoundTestNetLog log; |
| 2970 | session_deps_.net_log = log.bound().net_log(); |
| 2971 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2972 | |
| 2973 | scoped_ptr<HttpTransaction> trans( |
| 2974 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2975 | |
| 2976 | // Since we have proxy, should try to establish tunnel. |
| 2977 | MockWrite data_writes1[] = { |
| 2978 | MockWrite(ASYNC, 0, |
| 2979 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2980 | "Host: www.example.org:443\r\n" |
| 2981 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2982 | |
| 2983 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2984 | // be issuing -- the final header line contains the credentials. |
| 2985 | MockWrite(ASYNC, 3, |
| 2986 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2987 | "Host: www.example.org:443\r\n" |
| 2988 | "Proxy-Connection: keep-alive\r\n" |
| 2989 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 2990 | }; |
| 2991 | |
| 2992 | // The proxy responds to the connect with a 407, using a persistent |
| 2993 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 2994 | MockRead data_reads1[] = { |
| 2995 | // No credentials. |
| 2996 | MockRead(ASYNC, 1, |
| 2997 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 2998 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 2999 | "Content-Length: 10\r\n\r\n"), |
| 3000 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3001 | |
| 3002 | // Wrong credentials (wrong password). |
| 3003 | MockRead(ASYNC, 4, |
| 3004 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3005 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3006 | "Content-Length: 10\r\n\r\n"), |
| 3007 | // No response body because the test stops reading here. |
| 3008 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3009 | }; |
| 3010 | |
| 3011 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3012 | arraysize(data_writes1)); |
| 3013 | data1.set_busy_before_sync_reads(true); |
| 3014 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3015 | |
| 3016 | TestCompletionCallback callback1; |
| 3017 | |
| 3018 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 3019 | EXPECT_EQ(OK, callback1.GetResult(rv)); |
| 3020 | |
| 3021 | TestNetLogEntry::List entries; |
| 3022 | log.GetEntries(&entries); |
| 3023 | size_t pos = ExpectLogContainsSomewhere( |
| 3024 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3025 | NetLog::PHASE_NONE); |
| 3026 | ExpectLogContainsSomewhere( |
| 3027 | entries, pos, |
| 3028 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3029 | NetLog::PHASE_NONE); |
| 3030 | |
| 3031 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3032 | ASSERT_TRUE(response); |
| 3033 | ASSERT_TRUE(response->headers); |
| 3034 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3035 | EXPECT_EQ(407, response->headers->response_code()); |
| 3036 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3037 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3038 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3039 | |
| 3040 | TestCompletionCallback callback2; |
| 3041 | |
| 3042 | // Wrong password (should be "bar"). |
| 3043 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3044 | callback2.callback()); |
| 3045 | EXPECT_EQ(OK, callback2.GetResult(rv)); |
| 3046 | |
| 3047 | response = trans->GetResponseInfo(); |
| 3048 | ASSERT_TRUE(response); |
| 3049 | ASSERT_TRUE(response->headers); |
| 3050 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3051 | EXPECT_EQ(407, response->headers->response_code()); |
| 3052 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3053 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3054 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3055 | |
| 3056 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3057 | // out of scope. |
| 3058 | session->CloseAllConnections(); |
| 3059 | } |
| 3060 | } |
| 3061 | |
| 3062 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3063 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3064 | // the case the server sends extra data on the original socket, so it can't be |
| 3065 | // reused. |
| 3066 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3067 | HttpRequestInfo request; |
| 3068 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3069 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3070 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3071 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3072 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3073 | // Configure against proxy server "myproxy:70". |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3074 | session_deps_.proxy_service = |
| 3075 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3076 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3077 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3078 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3079 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3080 | // Since we have proxy, should try to establish tunnel. |
| 3081 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3082 | MockWrite(ASYNC, 0, |
| 3083 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3084 | "Host: www.example.org:443\r\n" |
| 3085 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3086 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3087 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3088 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3089 | // extra data, so the socket cannot be reused. |
| 3090 | MockRead data_reads1[] = { |
| 3091 | // No credentials. |
| 3092 | MockRead(ASYNC, 1, |
| 3093 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3094 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3095 | "Content-Length: 10\r\n\r\n"), |
| 3096 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3097 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3098 | }; |
| 3099 | |
| 3100 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3101 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3102 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3103 | MockWrite(ASYNC, 0, |
| 3104 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3105 | "Host: www.example.org:443\r\n" |
| 3106 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3107 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3108 | |
| 3109 | MockWrite(ASYNC, 2, |
| 3110 | "GET / HTTP/1.1\r\n" |
| 3111 | "Host: www.example.org\r\n" |
| 3112 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3113 | }; |
| 3114 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3115 | MockRead data_reads2[] = { |
| 3116 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3117 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3118 | MockRead(ASYNC, 3, |
| 3119 | "HTTP/1.1 200 OK\r\n" |
| 3120 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3121 | "Content-Length: 5\r\n\r\n"), |
| 3122 | // No response body because the test stops reading here. |
| 3123 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3124 | }; |
| 3125 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3126 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3127 | arraysize(data_writes1)); |
| 3128 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3129 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3130 | SequencedSocketData data2(data_reads2, arraysize(data_reads2), data_writes2, |
| 3131 | arraysize(data_writes2)); |
| 3132 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3133 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3134 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3135 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3136 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3137 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3138 | scoped_ptr<HttpTransaction> trans( |
| 3139 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3140 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3141 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 3142 | EXPECT_EQ(OK, callback1.GetResult(rv)); |
| 3143 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3144 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3145 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3146 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3147 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3148 | NetLog::PHASE_NONE); |
| 3149 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3150 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3151 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3152 | NetLog::PHASE_NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3153 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3154 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3155 | ASSERT_TRUE(response); |
| 3156 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3157 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3158 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3159 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3160 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3161 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3162 | LoadTimingInfo load_timing_info; |
| 3163 | // CONNECT requests and responses are handled at the connect job level, so |
| 3164 | // the transaction does not yet have a connection. |
| 3165 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3166 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3167 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3168 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3169 | rv = |
| 3170 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 3171 | EXPECT_EQ(OK, callback2.GetResult(rv)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3172 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3173 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3174 | EXPECT_EQ(200, response->headers->response_code()); |
| 3175 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3176 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3177 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3178 | // The password prompt info should not be set. |
| 3179 | EXPECT_FALSE(response->auth_challenge); |
| 3180 | |
| 3181 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3182 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3183 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3184 | |
| 3185 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3186 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3187 | } |
| 3188 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3189 | // Test the case a proxy closes a socket while the challenge body is being |
| 3190 | // drained. |
| 3191 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
| 3192 | HttpRequestInfo request; |
| 3193 | request.method = "GET"; |
| 3194 | request.url = GURL("https://www.example.org/"); |
| 3195 | // Ensure that proxy authentication is attempted even |
| 3196 | // when the no authentication data flag is set. |
| 3197 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3198 | |
| 3199 | // Configure against proxy server "myproxy:70". |
| 3200 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3201 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3202 | |
| 3203 | scoped_ptr<HttpTransaction> trans( |
| 3204 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3205 | |
| 3206 | // Since we have proxy, should try to establish tunnel. |
| 3207 | MockWrite data_writes1[] = { |
| 3208 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3209 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3210 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3211 | }; |
| 3212 | |
| 3213 | // The proxy responds to the connect with a 407, using a persistent |
| 3214 | // connection. |
| 3215 | MockRead data_reads1[] = { |
| 3216 | // No credentials. |
| 3217 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3218 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3219 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3220 | // Server hands up in the middle of the body. |
| 3221 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3222 | }; |
| 3223 | |
| 3224 | MockWrite data_writes2[] = { |
| 3225 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3226 | // be issuing -- the final header line contains the credentials. |
| 3227 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3228 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3229 | "Proxy-Connection: keep-alive\r\n" |
| 3230 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3231 | |
| 3232 | MockWrite("GET / HTTP/1.1\r\n" |
| 3233 | "Host: www.example.org\r\n" |
| 3234 | "Connection: keep-alive\r\n\r\n"), |
| 3235 | }; |
| 3236 | |
| 3237 | MockRead data_reads2[] = { |
| 3238 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3239 | |
| 3240 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3241 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3242 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3243 | MockRead(SYNCHRONOUS, "hello"), |
| 3244 | }; |
| 3245 | |
| 3246 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3247 | data_writes1, arraysize(data_writes1)); |
| 3248 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3249 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3250 | data_writes2, arraysize(data_writes2)); |
| 3251 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3252 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3253 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3254 | |
| 3255 | TestCompletionCallback callback; |
| 3256 | |
| 3257 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3258 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3259 | |
| 3260 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3261 | ASSERT_TRUE(response); |
| 3262 | ASSERT_TRUE(response->headers); |
| 3263 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3264 | EXPECT_EQ(407, response->headers->response_code()); |
| 3265 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3266 | |
| 3267 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 3268 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3269 | |
| 3270 | response = trans->GetResponseInfo(); |
| 3271 | ASSERT_TRUE(response); |
| 3272 | ASSERT_TRUE(response->headers); |
| 3273 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3274 | EXPECT_EQ(200, response->headers->response_code()); |
| 3275 | std::string body; |
| 3276 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &body)); |
| 3277 | EXPECT_EQ("hello", body); |
| 3278 | } |
| 3279 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3280 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3281 | // even if the user cancels the proxy's auth attempt. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3282 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3283 | HttpRequestInfo request; |
| 3284 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3285 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3286 | request.load_flags = 0; |
| 3287 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3288 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3289 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3290 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3291 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3292 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3293 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3294 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3295 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3296 | // Since we have proxy, should try to establish tunnel. |
| 3297 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3298 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3299 | "Host: www.example.org:443\r\n" |
| 3300 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3301 | }; |
| 3302 | |
| 3303 | // The proxy responds to the connect with a 407. |
| 3304 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3305 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3306 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3307 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3308 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3309 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3310 | }; |
| 3311 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3312 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 3313 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3314 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3315 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3316 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3317 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3318 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3319 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3320 | |
| 3321 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3322 | EXPECT_EQ(OK, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3323 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3324 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3325 | ASSERT_TRUE(response); |
| 3326 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3327 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3328 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3329 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3330 | |
| 3331 | std::string response_data; |
| 3332 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3333 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3334 | |
| 3335 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3336 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3337 | } |
| 3338 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3339 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3340 | // caller when the proxy responds to CONNECT with 407. |
| 3341 | TEST_P(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
| 3342 | HttpRequestInfo request; |
| 3343 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3344 | request.url = GURL("https://www.example.org/"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3345 | request.load_flags = 0; |
| 3346 | |
| 3347 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3348 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3349 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3350 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3351 | |
| 3352 | scoped_ptr<HttpTransaction> trans( |
| 3353 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3354 | |
| 3355 | // Since we have proxy, should try to establish tunnel. |
| 3356 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3357 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3358 | "Host: www.example.org:443\r\n" |
| 3359 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3360 | }; |
| 3361 | |
| 3362 | // The proxy responds to the connect with a 407. |
| 3363 | MockRead data_reads[] = { |
| 3364 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3365 | MockRead("X-Foo: bar\r\n"), |
| 3366 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 3367 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3368 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3369 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3370 | }; |
| 3371 | |
| 3372 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 3373 | arraysize(data_writes)); |
| 3374 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3375 | |
| 3376 | TestCompletionCallback callback; |
| 3377 | |
| 3378 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3379 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3380 | |
| 3381 | rv = callback.WaitForResult(); |
| 3382 | EXPECT_EQ(OK, rv); |
| 3383 | |
| 3384 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3385 | ASSERT_TRUE(response); |
| 3386 | ASSERT_TRUE(response->headers); |
| 3387 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3388 | EXPECT_EQ(407, response->headers->response_code()); |
| 3389 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3390 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 3391 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 3392 | |
| 3393 | std::string response_data; |
| 3394 | rv = ReadTransaction(trans.get(), &response_data); |
| 3395 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 3396 | |
| 3397 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 3398 | session->CloseAllConnections(); |
| 3399 | } |
| 3400 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3401 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 3402 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3403 | TEST_P(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3404 | HttpRequestInfo request; |
| 3405 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3406 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3407 | request.load_flags = 0; |
| 3408 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3409 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3410 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3411 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 3412 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3413 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3414 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3415 | MockWrite( |
| 3416 | "GET / HTTP/1.1\r\n" |
| 3417 | "Host: www.example.org\r\n" |
| 3418 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3419 | }; |
| 3420 | |
| 3421 | MockRead data_reads1[] = { |
| 3422 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 3423 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3424 | // Large content-length -- won't matter, as connection will be reset. |
| 3425 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3426 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3427 | }; |
| 3428 | |
| 3429 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3430 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3431 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3432 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3433 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3434 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3435 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3436 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3437 | |
| 3438 | rv = callback.WaitForResult(); |
| 3439 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
| 3440 | } |
| 3441 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3442 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3443 | // through a non-authenticating proxy. The request should fail with |
| 3444 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3445 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3446 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3447 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3448 | // issued the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3449 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3450 | HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3451 | HttpRequestInfo request; |
| 3452 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3453 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3454 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3455 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3456 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3457 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3458 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3459 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3460 | // Since we have proxy, should try to establish tunnel. |
| 3461 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3462 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3463 | "Host: www.example.org:443\r\n" |
| 3464 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3465 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3466 | MockWrite("GET / HTTP/1.1\r\n" |
| 3467 | "Host: www.example.org\r\n" |
| 3468 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3469 | }; |
| 3470 | |
| 3471 | MockRead data_reads1[] = { |
| 3472 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3473 | |
| 3474 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3475 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3476 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3477 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3478 | }; |
| 3479 | |
| 3480 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3481 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3482 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3483 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3484 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3485 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3486 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3487 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3488 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3489 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3490 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3491 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3492 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3493 | |
| 3494 | rv = callback1.WaitForResult(); |
| 3495 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3496 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3497 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3498 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3499 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3500 | NetLog::PHASE_NONE); |
| 3501 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3502 | entries, pos, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3503 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3504 | NetLog::PHASE_NONE); |
| 3505 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3506 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3507 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3508 | // that uses non-persistent connections. |
| 3509 | TEST_P(HttpNetworkTransactionTest, |
| 3510 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 3511 | HttpRequestInfo request; |
| 3512 | request.method = "GET"; |
| 3513 | request.url = GURL("https://www.example.org/"); |
| 3514 | |
| 3515 | // Configure against proxy server "myproxy:70". |
| 3516 | session_deps_.proxy_service = |
| 3517 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3518 | |
| 3519 | scoped_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
| 3520 | new HttpAuthHandlerMock::Factory()); |
| 3521 | auth_handler_factory->set_do_init_from_challenge(true); |
| 3522 | scoped_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
| 3523 | mock_handler->set_allows_default_credentials(true); |
| 3524 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3525 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3526 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3527 | |
| 3528 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3529 | NetLog net_log; |
| 3530 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3531 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3532 | |
| 3533 | // Since we have proxy, should try to establish tunnel. |
| 3534 | MockWrite data_writes1[] = { |
| 3535 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3536 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3537 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3538 | }; |
| 3539 | |
| 3540 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3541 | // connection. |
| 3542 | MockRead data_reads1[] = { |
| 3543 | // No credentials. |
| 3544 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3545 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3546 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3547 | }; |
| 3548 | |
| 3549 | // Since the first connection couldn't be reused, need to establish another |
| 3550 | // once given credentials. |
| 3551 | MockWrite data_writes2[] = { |
| 3552 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3553 | // be issuing -- the final header line contains the credentials. |
| 3554 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3555 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3556 | "Proxy-Connection: keep-alive\r\n" |
| 3557 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3558 | |
| 3559 | MockWrite("GET / HTTP/1.1\r\n" |
| 3560 | "Host: www.example.org\r\n" |
| 3561 | "Connection: keep-alive\r\n\r\n"), |
| 3562 | }; |
| 3563 | |
| 3564 | MockRead data_reads2[] = { |
| 3565 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3566 | |
| 3567 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3568 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3569 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3570 | MockRead(SYNCHRONOUS, "hello"), |
| 3571 | }; |
| 3572 | |
| 3573 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3574 | data_writes1, arraysize(data_writes1)); |
| 3575 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3576 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3577 | data_writes2, arraysize(data_writes2)); |
| 3578 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3579 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3580 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3581 | |
| 3582 | scoped_ptr<HttpTransaction> trans( |
| 3583 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3584 | |
| 3585 | TestCompletionCallback callback; |
| 3586 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3587 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3588 | |
| 3589 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3590 | ASSERT_TRUE(response); |
| 3591 | ASSERT_TRUE(response->headers); |
| 3592 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 3593 | EXPECT_EQ(407, response->headers->response_code()); |
| 3594 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3595 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 3596 | EXPECT_FALSE(response->auth_challenge.get()); |
| 3597 | |
| 3598 | LoadTimingInfo load_timing_info; |
| 3599 | // CONNECT requests and responses are handled at the connect job level, so |
| 3600 | // the transaction does not yet have a connection. |
| 3601 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3602 | |
| 3603 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 3604 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3605 | response = trans->GetResponseInfo(); |
| 3606 | ASSERT_TRUE(response); |
| 3607 | ASSERT_TRUE(response->headers); |
| 3608 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3609 | EXPECT_EQ(200, response->headers->response_code()); |
| 3610 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3611 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3612 | |
| 3613 | // The password prompt info should not be set. |
| 3614 | EXPECT_FALSE(response->auth_challenge); |
| 3615 | |
| 3616 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3617 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3618 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3619 | |
| 3620 | trans.reset(); |
| 3621 | session->CloseAllConnections(); |
| 3622 | } |
| 3623 | |
| 3624 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3625 | // that hangs up when credentials are initially sent. |
| 3626 | TEST_P(HttpNetworkTransactionTest, |
| 3627 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 3628 | HttpRequestInfo request; |
| 3629 | request.method = "GET"; |
| 3630 | request.url = GURL("https://www.example.org/"); |
| 3631 | |
| 3632 | // Configure against proxy server "myproxy:70". |
| 3633 | session_deps_.proxy_service = |
| 3634 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3635 | |
| 3636 | scoped_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
| 3637 | new HttpAuthHandlerMock::Factory()); |
| 3638 | auth_handler_factory->set_do_init_from_challenge(true); |
| 3639 | scoped_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
| 3640 | mock_handler->set_allows_default_credentials(true); |
| 3641 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3642 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3643 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3644 | |
| 3645 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3646 | NetLog net_log; |
| 3647 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3648 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3649 | |
| 3650 | // Should try to establish tunnel. |
| 3651 | MockWrite data_writes1[] = { |
| 3652 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3653 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3654 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3655 | |
| 3656 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3657 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3658 | "Proxy-Connection: keep-alive\r\n" |
| 3659 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3660 | }; |
| 3661 | |
| 3662 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3663 | // connection. |
| 3664 | MockRead data_reads1[] = { |
| 3665 | // No credentials. |
| 3666 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3667 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 3668 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 3669 | }; |
| 3670 | |
| 3671 | // Since the first connection was closed, need to establish another once given |
| 3672 | // credentials. |
| 3673 | MockWrite data_writes2[] = { |
| 3674 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3675 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3676 | "Proxy-Connection: keep-alive\r\n" |
| 3677 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3678 | |
| 3679 | MockWrite("GET / HTTP/1.1\r\n" |
| 3680 | "Host: www.example.org\r\n" |
| 3681 | "Connection: keep-alive\r\n\r\n"), |
| 3682 | }; |
| 3683 | |
| 3684 | MockRead data_reads2[] = { |
| 3685 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3686 | |
| 3687 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3688 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3689 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3690 | MockRead(SYNCHRONOUS, "hello"), |
| 3691 | }; |
| 3692 | |
| 3693 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3694 | data_writes1, arraysize(data_writes1)); |
| 3695 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3696 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3697 | data_writes2, arraysize(data_writes2)); |
| 3698 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3699 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3700 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3701 | |
| 3702 | scoped_ptr<HttpTransaction> trans( |
| 3703 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3704 | |
| 3705 | TestCompletionCallback callback; |
| 3706 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3707 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3708 | |
| 3709 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3710 | ASSERT_TRUE(response); |
| 3711 | ASSERT_TRUE(response->headers); |
| 3712 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3713 | EXPECT_EQ(407, response->headers->response_code()); |
| 3714 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3715 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 3716 | EXPECT_FALSE(response->auth_challenge); |
| 3717 | |
| 3718 | LoadTimingInfo load_timing_info; |
| 3719 | // CONNECT requests and responses are handled at the connect job level, so |
| 3720 | // the transaction does not yet have a connection. |
| 3721 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3722 | |
| 3723 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 3724 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3725 | |
| 3726 | response = trans->GetResponseInfo(); |
| 3727 | ASSERT_TRUE(response); |
| 3728 | ASSERT_TRUE(response->headers); |
| 3729 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3730 | EXPECT_EQ(200, response->headers->response_code()); |
| 3731 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3732 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3733 | |
| 3734 | // The password prompt info should not be set. |
| 3735 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 3736 | |
| 3737 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3738 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3739 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3740 | |
| 3741 | trans.reset(); |
| 3742 | session->CloseAllConnections(); |
| 3743 | } |
| 3744 | |
| 3745 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3746 | // that hangs up when credentials are initially sent, and hangs up again when |
| 3747 | // they are retried. |
| 3748 | TEST_P(HttpNetworkTransactionTest, |
| 3749 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 3750 | HttpRequestInfo request; |
| 3751 | request.method = "GET"; |
| 3752 | request.url = GURL("https://www.example.org/"); |
| 3753 | |
| 3754 | // Configure against proxy server "myproxy:70". |
| 3755 | session_deps_.proxy_service = |
| 3756 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3757 | |
| 3758 | scoped_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
| 3759 | new HttpAuthHandlerMock::Factory()); |
| 3760 | auth_handler_factory->set_do_init_from_challenge(true); |
| 3761 | scoped_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
| 3762 | mock_handler->set_allows_default_credentials(true); |
| 3763 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3764 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3765 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3766 | |
| 3767 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3768 | NetLog net_log; |
| 3769 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3770 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3771 | |
| 3772 | // Should try to establish tunnel. |
| 3773 | MockWrite data_writes1[] = { |
| 3774 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3775 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3776 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3777 | |
| 3778 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3779 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3780 | "Proxy-Connection: keep-alive\r\n" |
| 3781 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3782 | }; |
| 3783 | |
| 3784 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 3785 | // second request is sent. |
| 3786 | MockRead data_reads1[] = { |
| 3787 | // No credentials. |
| 3788 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3789 | MockRead("Content-Length: 0\r\n"), |
| 3790 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 3791 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 3792 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 3793 | }; |
| 3794 | |
| 3795 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 3796 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 3797 | // request. |
| 3798 | MockWrite data_writes2[] = { |
| 3799 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3800 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3801 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3802 | }; |
| 3803 | |
| 3804 | // The proxy, having had more than enough of us, just hangs up. |
| 3805 | MockRead data_reads2[] = { |
| 3806 | // No credentials. |
| 3807 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 3808 | }; |
| 3809 | |
| 3810 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3811 | data_writes1, arraysize(data_writes1)); |
| 3812 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3813 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3814 | data_writes2, arraysize(data_writes2)); |
| 3815 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3816 | |
| 3817 | scoped_ptr<HttpTransaction> trans( |
| 3818 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3819 | |
| 3820 | TestCompletionCallback callback; |
| 3821 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3822 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3823 | |
| 3824 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3825 | ASSERT_TRUE(response); |
| 3826 | ASSERT_TRUE(response->headers); |
| 3827 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3828 | EXPECT_EQ(407, response->headers->response_code()); |
| 3829 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3830 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 3831 | EXPECT_FALSE(response->auth_challenge); |
| 3832 | |
| 3833 | LoadTimingInfo load_timing_info; |
| 3834 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3835 | |
| 3836 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 3837 | EXPECT_EQ(ERR_EMPTY_RESPONSE, callback.GetResult(rv)); |
| 3838 | |
| 3839 | trans.reset(); |
| 3840 | session->CloseAllConnections(); |
| 3841 | } |
| 3842 | |
| 3843 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3844 | // that hangs up when credentials are initially sent, and sends a challenge |
| 3845 | // again they are retried. |
| 3846 | TEST_P(HttpNetworkTransactionTest, |
| 3847 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 3848 | HttpRequestInfo request; |
| 3849 | request.method = "GET"; |
| 3850 | request.url = GURL("https://www.example.org/"); |
| 3851 | |
| 3852 | // Configure against proxy server "myproxy:70". |
| 3853 | session_deps_.proxy_service = |
| 3854 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3855 | |
| 3856 | scoped_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
| 3857 | new HttpAuthHandlerMock::Factory()); |
| 3858 | auth_handler_factory->set_do_init_from_challenge(true); |
| 3859 | scoped_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
| 3860 | mock_handler->set_allows_default_credentials(true); |
| 3861 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3862 | HttpAuth::AUTH_PROXY); |
| 3863 | // Add another handler for the second challenge. It supports default |
| 3864 | // credentials, but they shouldn't be used, since they were already tried. |
| 3865 | mock_handler.reset(new HttpAuthHandlerMock()); |
| 3866 | mock_handler->set_allows_default_credentials(true); |
| 3867 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3868 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3869 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3870 | |
| 3871 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3872 | NetLog net_log; |
| 3873 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3874 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3875 | |
| 3876 | // Should try to establish tunnel. |
| 3877 | MockWrite data_writes1[] = { |
| 3878 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3879 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3880 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3881 | }; |
| 3882 | |
| 3883 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3884 | // connection. |
| 3885 | MockRead data_reads1[] = { |
| 3886 | // No credentials. |
| 3887 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3888 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3889 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3890 | }; |
| 3891 | |
| 3892 | // Since the first connection was closed, need to establish another once given |
| 3893 | // credentials. |
| 3894 | MockWrite data_writes2[] = { |
| 3895 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3896 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3897 | "Proxy-Connection: keep-alive\r\n" |
| 3898 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3899 | }; |
| 3900 | |
| 3901 | MockRead data_reads2[] = { |
| 3902 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3903 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3904 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3905 | }; |
| 3906 | |
| 3907 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3908 | data_writes1, arraysize(data_writes1)); |
| 3909 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3910 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3911 | data_writes2, arraysize(data_writes2)); |
| 3912 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3913 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3914 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3915 | |
| 3916 | scoped_ptr<HttpTransaction> trans( |
| 3917 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3918 | |
| 3919 | TestCompletionCallback callback; |
| 3920 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3921 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3922 | |
| 3923 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3924 | ASSERT_TRUE(response); |
| 3925 | ASSERT_TRUE(response->headers); |
| 3926 | EXPECT_EQ(407, response->headers->response_code()); |
| 3927 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3928 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 3929 | EXPECT_FALSE(response->auth_challenge); |
| 3930 | |
| 3931 | LoadTimingInfo load_timing_info; |
| 3932 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3933 | |
| 3934 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 3935 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3936 | response = trans->GetResponseInfo(); |
| 3937 | ASSERT_TRUE(response); |
| 3938 | ASSERT_TRUE(response->headers); |
| 3939 | EXPECT_EQ(407, response->headers->response_code()); |
| 3940 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 3941 | EXPECT_TRUE(response->auth_challenge); |
| 3942 | |
| 3943 | trans.reset(); |
| 3944 | session->CloseAllConnections(); |
| 3945 | } |
| 3946 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3947 | // Test the load timing for HTTPS requests with an HTTP proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3948 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3949 | HttpRequestInfo request1; |
| 3950 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3951 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3952 | |
| 3953 | HttpRequestInfo request2; |
| 3954 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3955 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3956 | |
| 3957 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3958 | session_deps_.proxy_service = ProxyService::CreateFixed("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3959 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3960 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3961 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3962 | |
| 3963 | // Since we have proxy, should try to establish tunnel. |
| 3964 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3965 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3966 | "Host: www.example.org:443\r\n" |
| 3967 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3968 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3969 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 3970 | "Host: www.example.org\r\n" |
| 3971 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3972 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3973 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 3974 | "Host: www.example.org\r\n" |
| 3975 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3976 | }; |
| 3977 | |
| 3978 | // The proxy responds to the connect with a 407, using a persistent |
| 3979 | // connection. |
| 3980 | MockRead data_reads1[] = { |
| 3981 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3982 | |
| 3983 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3984 | MockRead("Content-Length: 1\r\n\r\n"), |
| 3985 | MockRead(SYNCHRONOUS, "1"), |
| 3986 | |
| 3987 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3988 | MockRead("Content-Length: 2\r\n\r\n"), |
| 3989 | MockRead(SYNCHRONOUS, "22"), |
| 3990 | }; |
| 3991 | |
| 3992 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3993 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3994 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3995 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3996 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3997 | |
| 3998 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3999 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4000 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4001 | |
| 4002 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 4003 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4004 | |
| 4005 | rv = callback1.WaitForResult(); |
| 4006 | EXPECT_EQ(OK, rv); |
| 4007 | |
| 4008 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 4009 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4010 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4011 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4012 | |
| 4013 | LoadTimingInfo load_timing_info1; |
| 4014 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4015 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4016 | |
| 4017 | trans1.reset(); |
| 4018 | |
| 4019 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4020 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4021 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4022 | |
| 4023 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 4024 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4025 | |
| 4026 | rv = callback2.WaitForResult(); |
| 4027 | EXPECT_EQ(OK, rv); |
| 4028 | |
| 4029 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 4030 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4031 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4032 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4033 | |
| 4034 | LoadTimingInfo load_timing_info2; |
| 4035 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4036 | TestLoadTimingReused(load_timing_info2); |
| 4037 | |
| 4038 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4039 | |
| 4040 | trans2.reset(); |
| 4041 | session->CloseAllConnections(); |
| 4042 | } |
| 4043 | |
| 4044 | // 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] | 4045 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4046 | HttpRequestInfo request1; |
| 4047 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4048 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4049 | |
| 4050 | HttpRequestInfo request2; |
| 4051 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4052 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4053 | |
| 4054 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4055 | session_deps_.proxy_service = |
| 4056 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4057 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4058 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4059 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4060 | |
| 4061 | // Since we have proxy, should try to establish tunnel. |
| 4062 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4063 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4064 | "Host: www.example.org:443\r\n" |
| 4065 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4066 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4067 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4068 | "Host: www.example.org\r\n" |
| 4069 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4070 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4071 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4072 | "Host: www.example.org\r\n" |
| 4073 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4074 | }; |
| 4075 | |
| 4076 | // The proxy responds to the connect with a 407, using a persistent |
| 4077 | // connection. |
| 4078 | MockRead data_reads1[] = { |
| 4079 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4080 | |
| 4081 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4082 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4083 | MockRead(SYNCHRONOUS, "1"), |
| 4084 | |
| 4085 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4086 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4087 | MockRead(SYNCHRONOUS, "22"), |
| 4088 | }; |
| 4089 | |
| 4090 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4091 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4092 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4093 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4094 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4095 | |
| 4096 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4097 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4098 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4099 | |
| 4100 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 4101 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4102 | |
| 4103 | rv = callback1.WaitForResult(); |
| 4104 | EXPECT_EQ(OK, rv); |
| 4105 | |
| 4106 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 4107 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4108 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4109 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4110 | |
| 4111 | LoadTimingInfo load_timing_info1; |
| 4112 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4113 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 4114 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4115 | |
| 4116 | trans1.reset(); |
| 4117 | |
| 4118 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4119 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4120 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4121 | |
| 4122 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 4123 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4124 | |
| 4125 | rv = callback2.WaitForResult(); |
| 4126 | EXPECT_EQ(OK, rv); |
| 4127 | |
| 4128 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 4129 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4130 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4131 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4132 | |
| 4133 | LoadTimingInfo load_timing_info2; |
| 4134 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4135 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 4136 | |
| 4137 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4138 | |
| 4139 | trans2.reset(); |
| 4140 | session->CloseAllConnections(); |
| 4141 | } |
| 4142 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4143 | // Test a simple get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4144 | TEST_P(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4145 | HttpRequestInfo request; |
| 4146 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4147 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4148 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4149 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4150 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4151 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4152 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4153 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4154 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4155 | // Since we have proxy, should use full url |
| 4156 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4157 | MockWrite( |
| 4158 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4159 | "Host: www.example.org\r\n" |
| 4160 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4161 | }; |
| 4162 | |
| 4163 | MockRead data_reads1[] = { |
| 4164 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4165 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4166 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4167 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4168 | }; |
| 4169 | |
| 4170 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4171 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4172 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4173 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4174 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4175 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4176 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4177 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4178 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4179 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4180 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4181 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4182 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4183 | |
| 4184 | rv = callback1.WaitForResult(); |
| 4185 | EXPECT_EQ(OK, rv); |
| 4186 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4187 | LoadTimingInfo load_timing_info; |
| 4188 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4189 | TestLoadTimingNotReused(load_timing_info, |
| 4190 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4191 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4192 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4193 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4194 | |
| 4195 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4196 | EXPECT_EQ(200, response->headers->response_code()); |
| 4197 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4198 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4199 | |
| 4200 | // The password prompt info should not be set. |
| 4201 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4202 | } |
| 4203 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4204 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4205 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4206 | HttpRequestInfo request; |
| 4207 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4208 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4209 | request.load_flags = 0; |
| 4210 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4211 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4212 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4213 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4214 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4215 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4216 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4217 | // fetch http://www.example.org/ via SPDY |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4218 | scoped_ptr<SpdySerializedFrame> req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4219 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, false)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4220 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4221 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4222 | scoped_ptr<SpdySerializedFrame> resp( |
| 4223 | spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
| 4224 | scoped_ptr<SpdySerializedFrame> data( |
| 4225 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4226 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4227 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4228 | }; |
| 4229 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4230 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4231 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4232 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4233 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4234 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4235 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4236 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4237 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4238 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4239 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4240 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4241 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4242 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4243 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4244 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4245 | |
| 4246 | rv = callback1.WaitForResult(); |
| 4247 | EXPECT_EQ(OK, rv); |
| 4248 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4249 | LoadTimingInfo load_timing_info; |
| 4250 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4251 | TestLoadTimingNotReused(load_timing_info, |
| 4252 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4253 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4254 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4255 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4256 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4257 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4258 | |
| 4259 | std::string response_data; |
| 4260 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4261 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4262 | } |
| 4263 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4264 | // Verifies that a session which races and wins against the owning transaction |
| 4265 | // (completing prior to host resolution), doesn't fail the transaction. |
| 4266 | // Regression test for crbug.com/334413. |
| 4267 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
| 4268 | HttpRequestInfo request; |
| 4269 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4270 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4271 | request.load_flags = 0; |
| 4272 | |
| 4273 | // Configure SPDY proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4274 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4275 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4276 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4277 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4278 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4279 | // Fetch http://www.example.org/ through the SPDY proxy. |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4280 | scoped_ptr<SpdySerializedFrame> req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4281 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, false)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4282 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4283 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4284 | scoped_ptr<SpdySerializedFrame> resp( |
| 4285 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4286 | scoped_ptr<SpdySerializedFrame> data( |
| 4287 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4288 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4289 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4290 | }; |
| 4291 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4292 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4293 | arraysize(spdy_writes)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4294 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 4295 | |
| 4296 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4297 | ssl.SetNextProto(GetProtocol()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4298 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4299 | |
| 4300 | TestCompletionCallback callback1; |
| 4301 | |
| 4302 | scoped_ptr<HttpTransaction> trans( |
| 4303 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 4304 | |
| 4305 | // Stall the hostname resolution begun by the transaction. |
| 4306 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 4307 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4308 | |
| 4309 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 4310 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4311 | |
| 4312 | // Race a session to the proxy, which completes first. |
| 4313 | session_deps_.host_resolver->set_ondemand_mode(false); |
| 4314 | SpdySessionKey key( |
| 4315 | HostPortPair("proxy", 70), ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 4316 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4317 | CreateSecureSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4318 | |
| 4319 | // Unstall the resolution begun by the transaction. |
| 4320 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4321 | session_deps_.host_resolver->ResolveAllPending(); |
| 4322 | |
| 4323 | EXPECT_FALSE(callback1.have_result()); |
| 4324 | rv = callback1.WaitForResult(); |
| 4325 | EXPECT_EQ(OK, rv); |
| 4326 | |
| 4327 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4328 | ASSERT_TRUE(response != NULL); |
| 4329 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4330 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4331 | |
| 4332 | std::string response_data; |
| 4333 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 4334 | EXPECT_EQ(kUploadData, response_data); |
| 4335 | } |
| 4336 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4337 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4338 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4339 | HttpRequestInfo request; |
| 4340 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4341 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4342 | request.load_flags = 0; |
| 4343 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4344 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4345 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4346 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4347 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4348 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4349 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4350 | // The first request will be a bare GET, the second request will be a |
| 4351 | // GET with a Proxy-Authorization header. |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4352 | scoped_ptr<SpdySerializedFrame> req_get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4353 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, false)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4354 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4355 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4356 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4357 | }; |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4358 | scoped_ptr<SpdySerializedFrame> req_get_authorization( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4359 | spdy_util_.ConstructSpdyGet(kExtraAuthorizationHeaders, |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4360 | arraysize(kExtraAuthorizationHeaders) / 2, 3, |
| 4361 | LOWEST, false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4362 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4363 | CreateMockWrite(*req_get, 0), CreateMockWrite(*req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4364 | }; |
| 4365 | |
| 4366 | // The first response is a 407 proxy authentication challenge, and the second |
| 4367 | // response will be a 200 response since the second request includes a valid |
| 4368 | // Authorization header. |
| 4369 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4370 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4371 | }; |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4372 | scoped_ptr<SpdySerializedFrame> resp_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4373 | spdy_util_.ConstructSpdySynReplyError( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4374 | "407 Proxy Authentication Required", kExtraAuthenticationHeaders, |
| 4375 | arraysize(kExtraAuthenticationHeaders) / 2, 1)); |
| 4376 | scoped_ptr<SpdySerializedFrame> body_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4377 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4378 | scoped_ptr<SpdySerializedFrame> resp_data( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4379 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4380 | scoped_ptr<SpdySerializedFrame> body_data( |
| 4381 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4382 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4383 | CreateMockRead(*resp_authentication, 1), |
| 4384 | CreateMockRead(*body_authentication, 2), |
| 4385 | CreateMockRead(*resp_data, 4), |
| 4386 | CreateMockRead(*body_data, 5), |
| 4387 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4388 | }; |
| 4389 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4390 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4391 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4392 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4393 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4394 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4395 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4396 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4397 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4398 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4399 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4400 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4401 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4402 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4403 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4404 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4405 | |
| 4406 | rv = callback1.WaitForResult(); |
| 4407 | EXPECT_EQ(OK, rv); |
| 4408 | |
| 4409 | const HttpResponseInfo* const response = trans->GetResponseInfo(); |
| 4410 | |
| 4411 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4412 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4413 | EXPECT_EQ(407, response->headers->response_code()); |
| 4414 | EXPECT_TRUE(response->was_fetched_via_spdy); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4415 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4416 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4417 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4418 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4419 | rv = trans->RestartWithAuth( |
| 4420 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4421 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4422 | |
| 4423 | rv = callback2.WaitForResult(); |
| 4424 | EXPECT_EQ(OK, rv); |
| 4425 | |
| 4426 | const HttpResponseInfo* const response_restart = trans->GetResponseInfo(); |
| 4427 | |
| 4428 | ASSERT_TRUE(response_restart != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4429 | ASSERT_TRUE(response_restart->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4430 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 4431 | // The password prompt info should not be set. |
| 4432 | EXPECT_TRUE(response_restart->auth_challenge.get() == NULL); |
| 4433 | } |
| 4434 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4435 | // 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] | 4436 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4437 | HttpRequestInfo request; |
| 4438 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4439 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4440 | request.load_flags = 0; |
| 4441 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4442 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4443 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4444 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4445 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4446 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4447 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4448 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4449 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4450 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4451 | // CONNECT to www.example.org:443 via SPDY |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4452 | scoped_ptr<SpdySerializedFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4453 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4454 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4455 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4456 | const char get[] = |
| 4457 | "GET / HTTP/1.1\r\n" |
| 4458 | "Host: www.example.org\r\n" |
| 4459 | "Connection: keep-alive\r\n\r\n"; |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4460 | scoped_ptr<SpdySerializedFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4461 | spdy_util_.ConstructSpdyBodyFrame(1, get, strlen(get), false)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4462 | scoped_ptr<SpdySerializedFrame> conn_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4463 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4464 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 4465 | "Content-Length: 10\r\n\r\n"; |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4466 | scoped_ptr<SpdySerializedFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4467 | spdy_util_.ConstructSpdyBodyFrame(1, resp, strlen(resp), false)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4468 | scoped_ptr<SpdySerializedFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4469 | spdy_util_.ConstructSpdyBodyFrame(1, "1234567890", 10, false)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4470 | scoped_ptr<SpdySerializedFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4471 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4472 | |
| 4473 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4474 | CreateMockWrite(*connect, 0), |
| 4475 | CreateMockWrite(*wrapped_get, 2), |
| 4476 | CreateMockWrite(*window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4477 | }; |
| 4478 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4479 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4480 | CreateMockRead(*conn_resp, 1, ASYNC), |
| 4481 | CreateMockRead(*wrapped_get_resp, 3, ASYNC), |
| 4482 | CreateMockRead(*wrapped_body, 4, ASYNC), |
| 4483 | CreateMockRead(*wrapped_body, 5, ASYNC), |
| 4484 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4485 | }; |
| 4486 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4487 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4488 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4489 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4490 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4491 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4492 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4493 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4494 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4495 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4496 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4497 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4498 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4499 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4500 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4501 | |
| 4502 | rv = callback1.WaitForResult(); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4503 | ASSERT_EQ(OK, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4504 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4505 | LoadTimingInfo load_timing_info; |
| 4506 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4507 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4508 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4509 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4510 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4511 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4512 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4513 | |
| 4514 | std::string response_data; |
| 4515 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 4516 | EXPECT_EQ("1234567890", response_data); |
| 4517 | } |
| 4518 | |
| 4519 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4520 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4521 | SpdyTestUtil spdy_util_wrapped(GetProtocol(), GetDependenciesFromPriority()); |
| 4522 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4523 | HttpRequestInfo request; |
| 4524 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4525 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4526 | request.load_flags = 0; |
| 4527 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4528 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4529 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4530 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4531 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4532 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4533 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4534 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4535 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4536 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4537 | // CONNECT to www.example.org:443 via SPDY |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4538 | scoped_ptr<SpdySerializedFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4539 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4540 | // fetch https://www.example.org/ via SPDY |
| 4541 | const char kMyUrl[] = "https://www.example.org/"; |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4542 | scoped_ptr<SpdySerializedFrame> get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4543 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4544 | scoped_ptr<SpdySerializedFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4545 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4546 | scoped_ptr<SpdySerializedFrame> conn_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4547 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4548 | scoped_ptr<SpdySerializedFrame> get_resp( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4549 | spdy_util_wrapped.ConstructSpdyGetSynReply(NULL, 0, 1)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4550 | scoped_ptr<SpdySerializedFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4551 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4552 | scoped_ptr<SpdySerializedFrame> body( |
| 4553 | spdy_util_wrapped.ConstructSpdyBodyFrame(1, true)); |
| 4554 | scoped_ptr<SpdySerializedFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4555 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4556 | scoped_ptr<SpdySerializedFrame> window_update_get_resp( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4557 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4558 | scoped_ptr<SpdySerializedFrame> window_update_body( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4559 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4560 | |
| 4561 | MockWrite spdy_writes[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4562 | CreateMockWrite(*connect, 0), |
| 4563 | CreateMockWrite(*wrapped_get, 2), |
| 4564 | CreateMockWrite(*window_update_get_resp, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4565 | CreateMockWrite(*window_update_body, 7), |
| 4566 | }; |
| 4567 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4568 | MockRead spdy_reads[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4569 | CreateMockRead(*conn_resp, 1, ASYNC), |
| 4570 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4571 | CreateMockRead(*wrapped_get_resp, 4, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4572 | CreateMockRead(*wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4573 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4574 | }; |
| 4575 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4576 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4577 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4578 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4579 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4580 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4581 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4582 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4583 | SSLSocketDataProvider ssl2(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4584 | ssl2.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4585 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4586 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4587 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4588 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4589 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4590 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4591 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4592 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 4593 | base::MessageLoop::current()->RunUntilIdle(); |
| 4594 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 4595 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4596 | rv = callback1.WaitForResult(); |
| 4597 | EXPECT_EQ(OK, rv); |
| 4598 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4599 | LoadTimingInfo load_timing_info; |
| 4600 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4601 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4602 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4603 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4604 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4605 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4606 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4607 | |
| 4608 | std::string response_data; |
| 4609 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4610 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4611 | } |
| 4612 | |
| 4613 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4614 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4615 | HttpRequestInfo request; |
| 4616 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4617 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4618 | request.load_flags = 0; |
| 4619 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4620 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4621 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4622 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4623 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4624 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4625 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4626 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4627 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4628 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4629 | // CONNECT to www.example.org:443 via SPDY |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4630 | scoped_ptr<SpdySerializedFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4631 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4632 | scoped_ptr<SpdySerializedFrame> get( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4633 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4634 | |
| 4635 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4636 | CreateMockWrite(*connect, 0), CreateMockWrite(*get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4637 | }; |
| 4638 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4639 | scoped_ptr<SpdySerializedFrame> resp( |
| 4640 | spdy_util_.ConstructSpdySynReplyError(1)); |
| 4641 | scoped_ptr<SpdySerializedFrame> data( |
| 4642 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4643 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4644 | CreateMockRead(*resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4645 | }; |
| 4646 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4647 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4648 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4649 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4650 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4651 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4652 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4653 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4654 | SSLSocketDataProvider ssl2(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4655 | ssl2.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4656 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4657 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4658 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4659 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4660 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4661 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4662 | |
| 4663 | rv = callback1.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 4664 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4665 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 4666 | // TODO(ttuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4667 | } |
| 4668 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4669 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 4670 | // HTTPS Proxy to different servers. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4671 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4672 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 4673 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4674 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4675 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4676 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4677 | scoped_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4678 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4679 | |
| 4680 | HttpRequestInfo request1; |
| 4681 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4682 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4683 | request1.load_flags = 0; |
| 4684 | |
| 4685 | HttpRequestInfo request2; |
| 4686 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4687 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4688 | request2.load_flags = 0; |
| 4689 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4690 | // CONNECT to www.example.org:443 via SPDY. |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4691 | scoped_ptr<SpdySerializedFrame> connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4692 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4693 | scoped_ptr<SpdySerializedFrame> conn_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4694 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4695 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4696 | // Fetch https://www.example.org/ via HTTP. |
| 4697 | const char get1[] = |
| 4698 | "GET / HTTP/1.1\r\n" |
| 4699 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4700 | "Connection: keep-alive\r\n\r\n"; |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4701 | scoped_ptr<SpdySerializedFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4702 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4703 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 4704 | "Content-Length: 1\r\n\r\n"; |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4705 | scoped_ptr<SpdySerializedFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4706 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4707 | scoped_ptr<SpdySerializedFrame> wrapped_body1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4708 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4709 | scoped_ptr<SpdySerializedFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4710 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4711 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4712 | // CONNECT to mail.example.org:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4713 | SpdyHeaderBlock connect2_block; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 4714 | spdy_util_.MaybeAddVersionHeader(&connect2_block); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4715 | connect2_block[spdy_util_.GetMethodKey()] = "CONNECT"; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4716 | if (GetProtocol() == kProtoHTTP2) { |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 4717 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org:443"; |
| 4718 | } else { |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 4719 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 4720 | connect2_block[spdy_util_.GetPathKey()] = "mail.example.org:443"; |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 4721 | } |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4722 | scoped_ptr<SpdySerializedFrame> connect2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4723 | spdy_util_.ConstructSpdySyn(3, connect2_block, LOWEST, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 4724 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4725 | scoped_ptr<SpdySerializedFrame> conn_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4726 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4727 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4728 | // Fetch https://mail.example.org/ via HTTP. |
| 4729 | const char get2[] = |
| 4730 | "GET / HTTP/1.1\r\n" |
| 4731 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4732 | "Connection: keep-alive\r\n\r\n"; |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4733 | scoped_ptr<SpdySerializedFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4734 | spdy_util_.ConstructSpdyBodyFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4735 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 4736 | "Content-Length: 2\r\n\r\n"; |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4737 | scoped_ptr<SpdySerializedFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4738 | spdy_util_.ConstructSpdyBodyFrame(3, resp2, strlen(resp2), false)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4739 | scoped_ptr<SpdySerializedFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4740 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4741 | |
| 4742 | MockWrite spdy_writes[] = { |
| 4743 | CreateMockWrite(*connect1, 0), |
| 4744 | CreateMockWrite(*wrapped_get1, 2), |
| 4745 | CreateMockWrite(*connect2, 5), |
| 4746 | CreateMockWrite(*wrapped_get2, 7), |
| 4747 | }; |
| 4748 | |
| 4749 | MockRead spdy_reads[] = { |
| 4750 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 4751 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 4752 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 4753 | CreateMockRead(*conn_resp2, 6, ASYNC), |
| 4754 | CreateMockRead(*wrapped_get_resp2, 8, ASYNC), |
| 4755 | CreateMockRead(*wrapped_body2, 9, ASYNC), |
| 4756 | MockRead(ASYNC, 0, 10), |
| 4757 | }; |
| 4758 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4759 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4760 | arraysize(spdy_writes)); |
| 4761 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4762 | |
| 4763 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4764 | ssl.SetNextProto(GetProtocol()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4765 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4766 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4767 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4768 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4769 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4770 | |
| 4771 | TestCompletionCallback callback; |
| 4772 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4773 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4774 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4775 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4776 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4777 | |
| 4778 | LoadTimingInfo load_timing_info; |
| 4779 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4780 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4781 | |
| 4782 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4783 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4784 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4785 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4786 | |
| 4787 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4788 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4789 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 4790 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4791 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4792 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4793 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4794 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4795 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4796 | |
| 4797 | LoadTimingInfo load_timing_info2; |
| 4798 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4799 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 4800 | // to be created, so the socket's load timing looks like a fresh connection. |
| 4801 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4802 | |
| 4803 | // The requests should have different IDs, since they each are using their own |
| 4804 | // separate stream. |
| 4805 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4806 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4807 | rv = trans2->Read(buf.get(), 256, callback.callback()); |
| 4808 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4809 | } |
| 4810 | |
| 4811 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 4812 | // HTTPS Proxy to the same server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4813 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4814 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 4815 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4816 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4817 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4818 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4819 | scoped_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4820 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4821 | |
| 4822 | HttpRequestInfo request1; |
| 4823 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4824 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4825 | request1.load_flags = 0; |
| 4826 | |
| 4827 | HttpRequestInfo request2; |
| 4828 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4829 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4830 | request2.load_flags = 0; |
| 4831 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4832 | // CONNECT to www.example.org:443 via SPDY. |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4833 | scoped_ptr<SpdySerializedFrame> connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4834 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4835 | scoped_ptr<SpdySerializedFrame> conn_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4836 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4837 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4838 | // Fetch https://www.example.org/ via HTTP. |
| 4839 | const char get1[] = |
| 4840 | "GET / HTTP/1.1\r\n" |
| 4841 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4842 | "Connection: keep-alive\r\n\r\n"; |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4843 | scoped_ptr<SpdySerializedFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4844 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4845 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 4846 | "Content-Length: 1\r\n\r\n"; |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4847 | scoped_ptr<SpdySerializedFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4848 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4849 | scoped_ptr<SpdySerializedFrame> wrapped_body1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4850 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4851 | scoped_ptr<SpdySerializedFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4852 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4853 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4854 | // Fetch https://www.example.org/2 via HTTP. |
| 4855 | const char get2[] = |
| 4856 | "GET /2 HTTP/1.1\r\n" |
| 4857 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4858 | "Connection: keep-alive\r\n\r\n"; |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4859 | scoped_ptr<SpdySerializedFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4860 | spdy_util_.ConstructSpdyBodyFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4861 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 4862 | "Content-Length: 2\r\n\r\n"; |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4863 | scoped_ptr<SpdySerializedFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4864 | spdy_util_.ConstructSpdyBodyFrame(1, resp2, strlen(resp2), false)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4865 | scoped_ptr<SpdySerializedFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4866 | spdy_util_.ConstructSpdyBodyFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4867 | |
| 4868 | MockWrite spdy_writes[] = { |
| 4869 | CreateMockWrite(*connect1, 0), |
| 4870 | CreateMockWrite(*wrapped_get1, 2), |
| 4871 | CreateMockWrite(*wrapped_get2, 5), |
| 4872 | }; |
| 4873 | |
| 4874 | MockRead spdy_reads[] = { |
| 4875 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 4876 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 4877 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 4878 | CreateMockRead(*wrapped_get_resp2, 6, ASYNC), |
| 4879 | CreateMockRead(*wrapped_body2, 7, ASYNC), |
| 4880 | MockRead(ASYNC, 0, 8), |
| 4881 | }; |
| 4882 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4883 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4884 | arraysize(spdy_writes)); |
| 4885 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4886 | |
| 4887 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4888 | ssl.SetNextProto(GetProtocol()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4889 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4890 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4891 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4892 | |
| 4893 | TestCompletionCallback callback; |
| 4894 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4895 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4896 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4897 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 4898 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4899 | |
| 4900 | rv = callback.WaitForResult(); |
| 4901 | EXPECT_EQ(OK, rv); |
| 4902 | |
| 4903 | LoadTimingInfo load_timing_info; |
| 4904 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4905 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4906 | |
| 4907 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4908 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4909 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4910 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4911 | |
| 4912 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4913 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4914 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4915 | trans.reset(); |
| 4916 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4917 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4918 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4919 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 4920 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4921 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4922 | rv = callback.WaitForResult(); |
| 4923 | EXPECT_EQ(OK, rv); |
| 4924 | |
| 4925 | LoadTimingInfo load_timing_info2; |
| 4926 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4927 | TestLoadTimingReused(load_timing_info2); |
| 4928 | |
| 4929 | // The requests should have the same ID. |
| 4930 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4931 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4932 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4933 | } |
| 4934 | |
| 4935 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 4936 | // Proxy to different servers. |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4937 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4938 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4939 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4940 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4941 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4942 | scoped_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4943 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4944 | |
| 4945 | HttpRequestInfo request1; |
| 4946 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4947 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4948 | request1.load_flags = 0; |
| 4949 | |
| 4950 | HttpRequestInfo request2; |
| 4951 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4952 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4953 | request2.load_flags = 0; |
| 4954 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4955 | // http://www.example.org/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4956 | scoped_ptr<SpdyHeaderBlock> headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4957 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4958 | scoped_ptr<SpdySerializedFrame> get1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4959 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, true)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4960 | scoped_ptr<SpdySerializedFrame> get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4961 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4962 | scoped_ptr<SpdySerializedFrame> body1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4963 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4964 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4965 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4966 | // http://mail.example.org/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4967 | scoped_ptr<SpdyHeaderBlock> headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4968 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4969 | scoped_ptr<SpdySerializedFrame> get2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4970 | spdy_util_.ConstructSpdySyn(3, *headers2, LOWEST, true)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4971 | scoped_ptr<SpdySerializedFrame> get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4972 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 4973 | scoped_ptr<SpdySerializedFrame> body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4974 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4975 | |
| 4976 | MockWrite spdy_writes[] = { |
| 4977 | CreateMockWrite(*get1, 0), |
| 4978 | CreateMockWrite(*get2, 3), |
| 4979 | }; |
| 4980 | |
| 4981 | MockRead spdy_reads[] = { |
| 4982 | CreateMockRead(*get_resp1, 1, ASYNC), |
| 4983 | CreateMockRead(*body1, 2, ASYNC), |
| 4984 | CreateMockRead(*get_resp2, 4, ASYNC), |
| 4985 | CreateMockRead(*body2, 5, ASYNC), |
| 4986 | MockRead(ASYNC, 0, 6), |
| 4987 | }; |
| 4988 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4989 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4990 | arraysize(spdy_writes)); |
| 4991 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4992 | |
| 4993 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4994 | ssl.SetNextProto(GetProtocol()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4995 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4996 | |
| 4997 | TestCompletionCallback callback; |
| 4998 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4999 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5000 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5001 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5002 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5003 | |
| 5004 | LoadTimingInfo load_timing_info; |
| 5005 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5006 | TestLoadTimingNotReused(load_timing_info, |
| 5007 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5008 | |
| 5009 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5010 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5011 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5012 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5013 | |
| 5014 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5015 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5016 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5017 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5018 | // Delete the first request, so the second one can reuse the socket. |
| 5019 | trans.reset(); |
| 5020 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5021 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5022 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5023 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5024 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5025 | |
| 5026 | LoadTimingInfo load_timing_info2; |
| 5027 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5028 | TestLoadTimingReused(load_timing_info2); |
| 5029 | |
| 5030 | // The requests should have the same ID. |
| 5031 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5032 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5033 | rv = trans2->Read(buf.get(), 256, callback.callback()); |
| 5034 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5035 | } |
| 5036 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5037 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5038 | TEST_P(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5039 | HttpRequestInfo request; |
| 5040 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5041 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5042 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5043 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5044 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5045 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5046 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5047 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5048 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5049 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5050 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5051 | // Since we have proxy, should use full url |
| 5052 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 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\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5057 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5058 | // After calling trans->RestartWithAuth(), this is the request we should |
| 5059 | // be issuing -- the final header line contains the credentials. |
| 5060 | MockWrite( |
| 5061 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5062 | "Host: www.example.org\r\n" |
| 5063 | "Proxy-Connection: keep-alive\r\n" |
| 5064 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5065 | }; |
| 5066 | |
| 5067 | // The proxy responds to the GET with a 407, using a persistent |
| 5068 | // connection. |
| 5069 | MockRead data_reads1[] = { |
| 5070 | // No credentials. |
| 5071 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5072 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5073 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 5074 | MockRead("Content-Length: 0\r\n\r\n"), |
| 5075 | |
| 5076 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5077 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5078 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5079 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5080 | }; |
| 5081 | |
| 5082 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5083 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5084 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5085 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5086 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5087 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5088 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5089 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5090 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5091 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5092 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5093 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5094 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5095 | |
| 5096 | rv = callback1.WaitForResult(); |
| 5097 | EXPECT_EQ(OK, rv); |
| 5098 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5099 | LoadTimingInfo load_timing_info; |
| 5100 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5101 | TestLoadTimingNotReused(load_timing_info, |
| 5102 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5103 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5104 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5105 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5106 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5107 | EXPECT_EQ(407, response->headers->response_code()); |
| 5108 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5109 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5110 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5111 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5112 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5113 | rv = trans->RestartWithAuth( |
| 5114 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5115 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5116 | |
| 5117 | rv = callback2.WaitForResult(); |
| 5118 | EXPECT_EQ(OK, rv); |
| 5119 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5120 | load_timing_info = LoadTimingInfo(); |
| 5121 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5122 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 5123 | TestLoadTimingReused(load_timing_info); |
| 5124 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5125 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5126 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5127 | |
| 5128 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5129 | EXPECT_EQ(200, response->headers->response_code()); |
| 5130 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5131 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5132 | |
| 5133 | // The password prompt info should not be set. |
| 5134 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5135 | } |
| 5136 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5137 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5138 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5139 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5140 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5141 | request.url = GURL("https://www.example.org/"); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5142 | request.load_flags = 0; |
| 5143 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5144 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5145 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5146 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5147 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5148 | // Since we have proxy, should try to establish tunnel. |
| 5149 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5150 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5151 | "Host: www.example.org:443\r\n" |
| 5152 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5153 | }; |
| 5154 | |
| 5155 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 5156 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 5157 | // No response body because the test stops reading here. |
| 5158 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5159 | }; |
| 5160 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5161 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5162 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5163 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5164 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5165 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5166 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5167 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5168 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5169 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5170 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5171 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5172 | |
| 5173 | rv = callback.WaitForResult(); |
| 5174 | EXPECT_EQ(expected_status, rv); |
| 5175 | } |
| 5176 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5177 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5178 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5179 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5180 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5181 | } |
| 5182 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5183 | TEST_P(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5184 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 5185 | } |
| 5186 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5187 | TEST_P(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5188 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 5189 | } |
| 5190 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5191 | TEST_P(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5192 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 5193 | } |
| 5194 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5195 | TEST_P(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5196 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 5197 | } |
| 5198 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5199 | TEST_P(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5200 | ConnectStatusHelper( |
| 5201 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 5202 | } |
| 5203 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5204 | TEST_P(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5205 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 5206 | } |
| 5207 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5208 | TEST_P(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5209 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 5210 | } |
| 5211 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5212 | TEST_P(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5213 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 5214 | } |
| 5215 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5216 | TEST_P(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5217 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 5218 | } |
| 5219 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5220 | TEST_P(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5221 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 5222 | } |
| 5223 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5224 | TEST_P(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5225 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 5226 | } |
| 5227 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5228 | TEST_P(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5229 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 5230 | } |
| 5231 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5232 | TEST_P(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5233 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 5234 | } |
| 5235 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5236 | TEST_P(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5237 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 5238 | } |
| 5239 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5240 | TEST_P(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5241 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 5242 | } |
| 5243 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5244 | TEST_P(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5245 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 5246 | } |
| 5247 | |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 5248 | TEST_P(HttpNetworkTransactionTest, ConnectStatus308) { |
| 5249 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 5250 | } |
| 5251 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5252 | TEST_P(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5253 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 5254 | } |
| 5255 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5256 | TEST_P(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5257 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 5258 | } |
| 5259 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5260 | TEST_P(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5261 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 5262 | } |
| 5263 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5264 | TEST_P(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5265 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 5266 | } |
| 5267 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5268 | TEST_P(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5269 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 5270 | } |
| 5271 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5272 | TEST_P(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5273 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 5274 | } |
| 5275 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5276 | TEST_P(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5277 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 5278 | } |
| 5279 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5280 | TEST_P(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5281 | ConnectStatusHelperWithExpectedStatus( |
| 5282 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 5283 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5284 | } |
| 5285 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5286 | TEST_P(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5287 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 5288 | } |
| 5289 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5290 | TEST_P(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5291 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 5292 | } |
| 5293 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5294 | TEST_P(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5295 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 5296 | } |
| 5297 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5298 | TEST_P(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5299 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 5300 | } |
| 5301 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5302 | TEST_P(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5303 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 5304 | } |
| 5305 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5306 | TEST_P(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5307 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 5308 | } |
| 5309 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5310 | TEST_P(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5311 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 5312 | } |
| 5313 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5314 | TEST_P(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5315 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 5316 | } |
| 5317 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5318 | TEST_P(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5319 | ConnectStatusHelper( |
| 5320 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 5321 | } |
| 5322 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5323 | TEST_P(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5324 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 5325 | } |
| 5326 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5327 | TEST_P(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5328 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 5329 | } |
| 5330 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5331 | TEST_P(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5332 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 5333 | } |
| 5334 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5335 | TEST_P(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5336 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 5337 | } |
| 5338 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5339 | TEST_P(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5340 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 5341 | } |
| 5342 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5343 | TEST_P(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5344 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 5345 | } |
| 5346 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5347 | TEST_P(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5348 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 5349 | } |
| 5350 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5351 | // Test the flow when both the proxy server AND origin server require |
| 5352 | // authentication. Again, this uses basic auth for both since that is |
| 5353 | // the simplest to mock. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5354 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5355 | HttpRequestInfo request; |
| 5356 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5357 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5358 | request.load_flags = 0; |
| 5359 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5360 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5361 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5362 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5363 | |
| 5364 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5365 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5366 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5367 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5368 | MockWrite( |
| 5369 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5370 | "Host: www.example.org\r\n" |
| 5371 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5372 | }; |
| 5373 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5374 | MockRead data_reads1[] = { |
| 5375 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 5376 | // Give a couple authenticate options (only the middle one is actually |
| 5377 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 5378 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5379 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5380 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 5381 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5382 | // Large content-length -- won't matter, as connection will be reset. |
| 5383 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5384 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5385 | }; |
| 5386 | |
| 5387 | // After calling trans->RestartWithAuth() the first time, this is the |
| 5388 | // request we should be issuing -- the final header line contains the |
| 5389 | // proxy's credentials. |
| 5390 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5391 | MockWrite( |
| 5392 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5393 | "Host: www.example.org\r\n" |
| 5394 | "Proxy-Connection: keep-alive\r\n" |
| 5395 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5396 | }; |
| 5397 | |
| 5398 | // Now the proxy server lets the request pass through to origin server. |
| 5399 | // The origin server responds with a 401. |
| 5400 | MockRead data_reads2[] = { |
| 5401 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5402 | // Note: We are using the same realm-name as the proxy server. This is |
| 5403 | // completely valid, as realms are unique across hosts. |
| 5404 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5405 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5406 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5407 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5408 | }; |
| 5409 | |
| 5410 | // After calling trans->RestartWithAuth() the second time, we should send |
| 5411 | // the credentials for both the proxy and origin server. |
| 5412 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5413 | MockWrite( |
| 5414 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5415 | "Host: www.example.org\r\n" |
| 5416 | "Proxy-Connection: keep-alive\r\n" |
| 5417 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 5418 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5419 | }; |
| 5420 | |
| 5421 | // Lastly we get the desired content. |
| 5422 | MockRead data_reads3[] = { |
| 5423 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5424 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5425 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5426 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5427 | }; |
| 5428 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5429 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5430 | data_writes1, arraysize(data_writes1)); |
| 5431 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5432 | data_writes2, arraysize(data_writes2)); |
| 5433 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5434 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5435 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5436 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5437 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5438 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5439 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5440 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5441 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5442 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5443 | |
| 5444 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5445 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5446 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5447 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5448 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5449 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5450 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5451 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5452 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5453 | rv = trans->RestartWithAuth( |
| 5454 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5455 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5456 | |
| 5457 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5458 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5459 | |
| 5460 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5461 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5462 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5463 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5464 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5465 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5466 | rv = trans->RestartWithAuth( |
| 5467 | AuthCredentials(kFoo2, kBar2), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5468 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5469 | |
| 5470 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5471 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5472 | |
| 5473 | response = trans->GetResponseInfo(); |
| 5474 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5475 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5476 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5477 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5478 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 5479 | // can't hook into its internals to cause it to generate predictable NTLM |
| 5480 | // authorization headers. |
| 5481 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5482 | // The NTLM authentication unit tests were generated by capturing the HTTP |
| 5483 | // requests and responses using Fiddler 2 and inspecting the generated random |
| 5484 | // bytes in the debugger. |
| 5485 | |
| 5486 | // Enter the correct password and authenticate successfully. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5487 | TEST_P(HttpNetworkTransactionTest, NTLMAuth1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5488 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5489 | request.method = "GET"; |
| 5490 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5491 | |
| 5492 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 5493 | // to other auth schemes. |
| 5494 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5495 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5496 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 5497 | MockGetHostName); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5498 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5499 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5500 | MockWrite data_writes1[] = { |
| 5501 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5502 | "Host: 172.22.68.17\r\n" |
| 5503 | "Connection: keep-alive\r\n\r\n"), |
| 5504 | }; |
| 5505 | |
| 5506 | MockRead data_reads1[] = { |
| 5507 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 5508 | // Negotiate and NTLM are often requested together. However, we only want |
| 5509 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 5510 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5511 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5512 | MockRead("Connection: close\r\n"), |
| 5513 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5514 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5515 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5516 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5517 | }; |
| 5518 | |
| 5519 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5520 | // After restarting with a null identity, this is the |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5521 | // request we should be issuing -- the final header line contains a Type |
| 5522 | // 1 message. |
| 5523 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5524 | "Host: 172.22.68.17\r\n" |
| 5525 | "Connection: keep-alive\r\n" |
| 5526 | "Authorization: NTLM " |
| 5527 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 5528 | |
| 5529 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 5530 | // (the credentials for the origin server). The second request continues |
| 5531 | // on the same connection. |
| 5532 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5533 | "Host: 172.22.68.17\r\n" |
| 5534 | "Connection: keep-alive\r\n" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5535 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5536 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5537 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 5538 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 5539 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5540 | }; |
| 5541 | |
| 5542 | MockRead data_reads2[] = { |
| 5543 | // The origin server responds with a Type 2 message. |
| 5544 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5545 | MockRead("WWW-Authenticate: NTLM " |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5546 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5547 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5548 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5549 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5550 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5551 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5552 | "BtAAAAAAA=\r\n"), |
| 5553 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5554 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5555 | MockRead("You are not authorized to view this page\r\n"), |
| 5556 | |
| 5557 | // Lastly we get the desired content. |
| 5558 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5559 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 5560 | MockRead("Content-Length: 13\r\n\r\n"), |
| 5561 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5562 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5563 | }; |
| 5564 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5565 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5566 | data_writes1, arraysize(data_writes1)); |
| 5567 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5568 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5569 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5570 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5571 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5572 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5573 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5574 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5575 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5576 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5577 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5578 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5579 | |
| 5580 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5581 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5582 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5583 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5584 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5585 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5586 | ASSERT_FALSE(response == NULL); |
| 5587 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5588 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5589 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5590 | |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5591 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5592 | callback2.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5593 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5594 | |
| 5595 | rv = callback2.WaitForResult(); |
| 5596 | EXPECT_EQ(OK, rv); |
| 5597 | |
| 5598 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5599 | |
| 5600 | response = trans->GetResponseInfo(); |
| 5601 | ASSERT_TRUE(response != NULL); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5602 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5603 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5604 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5605 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5606 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5607 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5608 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5609 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5610 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5611 | |
| 5612 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5613 | ASSERT_TRUE(response != NULL); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5614 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5615 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 5616 | } |
| 5617 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5618 | // Enter a wrong password, and then the correct one. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5619 | TEST_P(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5620 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5621 | request.method = "GET"; |
| 5622 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 5623 | request.load_flags = 0; |
| 5624 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5625 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 5626 | MockGetHostName); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5627 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5628 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5629 | MockWrite data_writes1[] = { |
| 5630 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5631 | "Host: 172.22.68.17\r\n" |
| 5632 | "Connection: keep-alive\r\n\r\n"), |
| 5633 | }; |
| 5634 | |
| 5635 | MockRead data_reads1[] = { |
| 5636 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 5637 | // Negotiate and NTLM are often requested together. However, we only want |
| 5638 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 5639 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5640 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5641 | MockRead("Connection: close\r\n"), |
| 5642 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5643 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5644 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5645 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5646 | }; |
| 5647 | |
| 5648 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5649 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5650 | // request we should be issuing -- the final header line contains a Type |
| 5651 | // 1 message. |
| 5652 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5653 | "Host: 172.22.68.17\r\n" |
| 5654 | "Connection: keep-alive\r\n" |
| 5655 | "Authorization: NTLM " |
| 5656 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 5657 | |
| 5658 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 5659 | // (the credentials for the origin server). The second request continues |
| 5660 | // on the same connection. |
| 5661 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5662 | "Host: 172.22.68.17\r\n" |
| 5663 | "Connection: keep-alive\r\n" |
| 5664 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5665 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5666 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 5667 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 5668 | "4Ww7b7E=\r\n\r\n"), |
| 5669 | }; |
| 5670 | |
| 5671 | MockRead data_reads2[] = { |
| 5672 | // The origin server responds with a Type 2 message. |
| 5673 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5674 | MockRead("WWW-Authenticate: NTLM " |
| 5675 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 5676 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5677 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5678 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5679 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5680 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5681 | "BtAAAAAAA=\r\n"), |
| 5682 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5683 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5684 | MockRead("You are not authorized to view this page\r\n"), |
| 5685 | |
| 5686 | // Wrong password. |
| 5687 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5688 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5689 | MockRead("Connection: close\r\n"), |
| 5690 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5691 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5692 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5693 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5694 | }; |
| 5695 | |
| 5696 | MockWrite data_writes3[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5697 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5698 | // request we should be issuing -- the final header line contains a Type |
| 5699 | // 1 message. |
| 5700 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5701 | "Host: 172.22.68.17\r\n" |
| 5702 | "Connection: keep-alive\r\n" |
| 5703 | "Authorization: NTLM " |
| 5704 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 5705 | |
| 5706 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 5707 | // (the credentials for the origin server). The second request continues |
| 5708 | // on the same connection. |
| 5709 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5710 | "Host: 172.22.68.17\r\n" |
| 5711 | "Connection: keep-alive\r\n" |
| 5712 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5713 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5714 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 5715 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 5716 | "+4MUm7c=\r\n\r\n"), |
| 5717 | }; |
| 5718 | |
| 5719 | MockRead data_reads3[] = { |
| 5720 | // The origin server responds with a Type 2 message. |
| 5721 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5722 | MockRead("WWW-Authenticate: NTLM " |
| 5723 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 5724 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5725 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5726 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5727 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5728 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5729 | "BtAAAAAAA=\r\n"), |
| 5730 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5731 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5732 | MockRead("You are not authorized to view this page\r\n"), |
| 5733 | |
| 5734 | // Lastly we get the desired content. |
| 5735 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5736 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 5737 | MockRead("Content-Length: 13\r\n\r\n"), |
| 5738 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5739 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5740 | }; |
| 5741 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5742 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5743 | data_writes1, arraysize(data_writes1)); |
| 5744 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5745 | data_writes2, arraysize(data_writes2)); |
| 5746 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5747 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5748 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5749 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5750 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5751 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5752 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5753 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5754 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5755 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5756 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5757 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5758 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5759 | |
| 5760 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5761 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5762 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5763 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5764 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5765 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5766 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5767 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5768 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5769 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5770 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5771 | // Enter the wrong password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5772 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5773 | callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5774 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5775 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5776 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5777 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5778 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5779 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5780 | TestCompletionCallback callback3; |
| 5781 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5782 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5783 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5784 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5785 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5786 | |
| 5787 | response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5788 | ASSERT_FALSE(response == NULL); |
| 5789 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5790 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5791 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5792 | |
| 5793 | // Now enter the right password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5794 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5795 | callback4.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5796 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5797 | |
| 5798 | rv = callback4.WaitForResult(); |
| 5799 | EXPECT_EQ(OK, rv); |
| 5800 | |
| 5801 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5802 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5803 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5804 | |
| 5805 | // One more roundtrip |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5806 | rv = trans->RestartWithAuth(AuthCredentials(), callback5.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5807 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5808 | |
| 5809 | rv = callback5.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5810 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5811 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5812 | response = trans->GetResponseInfo(); |
| 5813 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5814 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 5815 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5816 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5817 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5818 | // Test reading a server response which has only headers, and no body. |
| 5819 | // After some maximum number of bytes is consumed, the transaction should |
| 5820 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5821 | TEST_P(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5822 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5823 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5824 | request.url = GURL("http://www.example.org/"); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5825 | request.load_flags = 0; |
| 5826 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5827 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5828 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5829 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5830 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 5831 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 5832 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 5833 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5834 | |
| 5835 | MockRead data_reads[] = { |
| 5836 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5837 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5838 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5839 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5840 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5841 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5842 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5843 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5844 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5845 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5846 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5847 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5848 | |
| 5849 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5850 | EXPECT_EQ(ERR_RESPONSE_HEADERS_TOO_BIG, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5851 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5852 | |
| 5853 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 5854 | // establish tunnel. |
| 5855 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5856 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5857 | DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5858 | HttpRequestInfo request; |
| 5859 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5860 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5861 | request.load_flags = 0; |
| 5862 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5863 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5864 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 5865 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5866 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5867 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5868 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5869 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5870 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5871 | // Since we have proxy, should try to establish tunnel. |
| 5872 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5873 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5874 | "Host: www.example.org:443\r\n" |
| 5875 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5876 | }; |
| 5877 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 5878 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5879 | // connection. Usually a proxy would return 501 (not implemented), |
| 5880 | // or 200 (tunnel established). |
| 5881 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 5882 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 5883 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5884 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5885 | }; |
| 5886 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5887 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5888 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5889 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5890 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5891 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5892 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5893 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5894 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5895 | |
| 5896 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5897 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5898 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5899 | // Empty the current queue. This is necessary because idle sockets are |
| 5900 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5901 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5902 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5903 | // We now check to make sure the TCPClientSocket was not added back to |
| 5904 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5905 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5906 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5907 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5908 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5909 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5910 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5911 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5912 | // 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] | 5913 | TEST_P(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5914 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5915 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5916 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5917 | request.load_flags = 0; |
| 5918 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5919 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5920 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5921 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5922 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5923 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5924 | MockRead data_reads[] = { |
| 5925 | // A part of the response body is received with the response headers. |
| 5926 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 5927 | // The rest of the response body is received in two parts. |
| 5928 | MockRead("lo"), |
| 5929 | MockRead(" world"), |
| 5930 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5931 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5932 | }; |
| 5933 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5934 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5935 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5936 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5937 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5938 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5939 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5940 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5941 | |
| 5942 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5943 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5944 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5945 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5946 | ASSERT_TRUE(response != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5947 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5948 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5949 | std::string status_line = response->headers->GetStatusLine(); |
| 5950 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 5951 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5952 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5953 | |
| 5954 | std::string response_data; |
| 5955 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5956 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5957 | EXPECT_EQ("hello world", response_data); |
| 5958 | |
| 5959 | // Empty the current queue. This is necessary because idle sockets are |
| 5960 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5961 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5962 | |
| 5963 | // 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] | 5964 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5965 | } |
| 5966 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5967 | // Make sure that we recycle a SSL socket after reading all of the response |
| 5968 | // body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5969 | TEST_P(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5970 | HttpRequestInfo request; |
| 5971 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5972 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5973 | request.load_flags = 0; |
| 5974 | |
| 5975 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5976 | MockWrite( |
| 5977 | "GET / HTTP/1.1\r\n" |
| 5978 | "Host: www.example.org\r\n" |
| 5979 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5980 | }; |
| 5981 | |
| 5982 | MockRead data_reads[] = { |
| 5983 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5984 | MockRead("Content-Length: 11\r\n\r\n"), |
| 5985 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5986 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5987 | }; |
| 5988 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5989 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5990 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5991 | |
| 5992 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5993 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5994 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5995 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5996 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5997 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5998 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5999 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6000 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6001 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6002 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6003 | |
| 6004 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6005 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 6006 | |
| 6007 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6008 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6009 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6010 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6011 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6012 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6013 | |
| 6014 | std::string response_data; |
| 6015 | rv = ReadTransaction(trans.get(), &response_data); |
| 6016 | EXPECT_EQ(OK, rv); |
| 6017 | EXPECT_EQ("hello world", response_data); |
| 6018 | |
| 6019 | // Empty the current queue. This is necessary because idle sockets are |
| 6020 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 6021 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6022 | |
| 6023 | // 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] | 6024 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6025 | } |
| 6026 | |
| 6027 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 6028 | // from the pool and make sure that we recover okay. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6029 | TEST_P(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6030 | HttpRequestInfo request; |
| 6031 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6032 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6033 | request.load_flags = 0; |
| 6034 | |
| 6035 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6036 | MockWrite( |
| 6037 | "GET / HTTP/1.1\r\n" |
| 6038 | "Host: www.example.org\r\n" |
| 6039 | "Connection: keep-alive\r\n\r\n"), |
| 6040 | MockWrite( |
| 6041 | "GET / HTTP/1.1\r\n" |
| 6042 | "Host: www.example.org\r\n" |
| 6043 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6044 | }; |
| 6045 | |
| 6046 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 6047 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6048 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6049 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6050 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6051 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6052 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6053 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6054 | |
| 6055 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6056 | data_writes, arraysize(data_writes)); |
| 6057 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 6058 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6059 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6060 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6061 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6062 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6063 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6064 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6065 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6066 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6067 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6068 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6069 | |
| 6070 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6071 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 6072 | |
| 6073 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6074 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6075 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6076 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6077 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6078 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6079 | |
| 6080 | std::string response_data; |
| 6081 | rv = ReadTransaction(trans.get(), &response_data); |
| 6082 | EXPECT_EQ(OK, rv); |
| 6083 | EXPECT_EQ("hello world", response_data); |
| 6084 | |
| 6085 | // Empty the current queue. This is necessary because idle sockets are |
| 6086 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 6087 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6088 | |
| 6089 | // 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] | 6090 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6091 | |
| 6092 | // Now start the second transaction, which should reuse the previous socket. |
| 6093 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6094 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6095 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6096 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6097 | |
| 6098 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6099 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 6100 | |
| 6101 | response = trans->GetResponseInfo(); |
| 6102 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6103 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6104 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6105 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6106 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6107 | |
| 6108 | rv = ReadTransaction(trans.get(), &response_data); |
| 6109 | EXPECT_EQ(OK, rv); |
| 6110 | EXPECT_EQ("hello world", response_data); |
| 6111 | |
| 6112 | // Empty the current queue. This is necessary because idle sockets are |
| 6113 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 6114 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6115 | |
| 6116 | // 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] | 6117 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6118 | } |
| 6119 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6120 | // Make sure that we recycle a socket after a zero-length response. |
| 6121 | // http://crbug.com/9880 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6122 | TEST_P(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6123 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6124 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6125 | request.url = GURL( |
| 6126 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 6127 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 6128 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 6129 | "rt=prt.2642,ol.2649,xjs.2951"); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6130 | request.load_flags = 0; |
| 6131 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6132 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6133 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6134 | MockRead data_reads[] = { |
| 6135 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 6136 | "Content-Length: 0\r\n" |
| 6137 | "Content-Type: text/html\r\n\r\n"), |
| 6138 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6139 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6140 | }; |
| 6141 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6142 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6143 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6144 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 6145 | // Transaction must be created after the MockReads, so it's destroyed before |
| 6146 | // them. |
| 6147 | scoped_ptr<HttpTransaction> trans( |
| 6148 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 6149 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6150 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6151 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6152 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6153 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6154 | |
| 6155 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6156 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6157 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6158 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6159 | ASSERT_TRUE(response != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6160 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6161 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6162 | std::string status_line = response->headers->GetStatusLine(); |
| 6163 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 6164 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6165 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6166 | |
| 6167 | std::string response_data; |
| 6168 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6169 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6170 | EXPECT_EQ("", response_data); |
| 6171 | |
| 6172 | // Empty the current queue. This is necessary because idle sockets are |
| 6173 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 6174 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6175 | |
| 6176 | // 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] | 6177 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6178 | } |
| 6179 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6180 | TEST_P(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6181 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 6182 | element_readers.push_back( |
| 6183 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 6184 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6185 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6186 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6187 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 6188 | // after use. |
| 6189 | request[0].method = "GET"; |
| 6190 | request[0].url = GURL("http://www.google.com/"); |
| 6191 | request[0].load_flags = 0; |
| 6192 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 6193 | // transaction 1. The first attempts fails when writing the POST data. |
| 6194 | // This causes the transaction to retry with a new socket. The second |
| 6195 | // attempt succeeds. |
| 6196 | request[1].method = "POST"; |
| 6197 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6198 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6199 | request[1].load_flags = 0; |
| 6200 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6201 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6202 | |
| 6203 | // The first socket is used for transaction 1 and the first attempt of |
| 6204 | // transaction 2. |
| 6205 | |
| 6206 | // The response of transaction 1. |
| 6207 | MockRead data_reads1[] = { |
| 6208 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 6209 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6210 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6211 | }; |
| 6212 | // The mock write results of transaction 1 and the first attempt of |
| 6213 | // transaction 2. |
| 6214 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6215 | MockWrite(SYNCHRONOUS, 64), // GET |
| 6216 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6217 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6218 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6219 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6220 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6221 | |
| 6222 | // The second socket is used for the second attempt of transaction 2. |
| 6223 | |
| 6224 | // The response of transaction 2. |
| 6225 | MockRead data_reads2[] = { |
| 6226 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 6227 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6228 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6229 | }; |
| 6230 | // The mock write results of the second attempt of transaction 2. |
| 6231 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6232 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6233 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6234 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6235 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6236 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6237 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6238 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6239 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6240 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 6241 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6242 | "hello world", "welcome" |
| 6243 | }; |
| 6244 | |
| 6245 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6246 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6247 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6248 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6249 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6250 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6251 | int rv = trans->Start(&request[i], callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6252 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6253 | |
| 6254 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6255 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6256 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6257 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6258 | ASSERT_TRUE(response != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6259 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6260 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6261 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6262 | |
| 6263 | std::string response_data; |
| 6264 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6265 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6266 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 6267 | } |
| 6268 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6269 | |
| 6270 | // Test the request-challenge-retry sequence for basic auth when there is |
| 6271 | // 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] | 6272 | // it fails the identity from the URL is used to answer the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6273 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6274 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6275 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6276 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 6277 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6278 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6279 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6280 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6281 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6282 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6283 | // The password contains an escaped character -- for this test to pass it |
| 6284 | // will need to be unescaped by HttpNetworkTransaction. |
| 6285 | EXPECT_EQ("b%40r", request.url.password()); |
| 6286 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6287 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6288 | MockWrite( |
| 6289 | "GET / HTTP/1.1\r\n" |
| 6290 | "Host: www.example.org\r\n" |
| 6291 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6292 | }; |
| 6293 | |
| 6294 | MockRead data_reads1[] = { |
| 6295 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6296 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6297 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6298 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6299 | }; |
| 6300 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6301 | // After the challenge above, the transaction will be restarted using the |
| 6302 | // identity from the url (foo, b@r) to answer the challenge. |
| 6303 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6304 | MockWrite( |
| 6305 | "GET / HTTP/1.1\r\n" |
| 6306 | "Host: www.example.org\r\n" |
| 6307 | "Connection: keep-alive\r\n" |
| 6308 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6309 | }; |
| 6310 | |
| 6311 | MockRead data_reads2[] = { |
| 6312 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6313 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6314 | MockRead(SYNCHRONOUS, OK), |
| 6315 | }; |
| 6316 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6317 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6318 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6319 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6320 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6321 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6322 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6323 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6324 | TestCompletionCallback callback1; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6325 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6326 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6327 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6328 | EXPECT_EQ(OK, rv); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6329 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 6330 | |
| 6331 | TestCompletionCallback callback2; |
| 6332 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 6333 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6334 | rv = callback2.WaitForResult(); |
| 6335 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6336 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6337 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6338 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6339 | ASSERT_TRUE(response != NULL); |
| 6340 | |
| 6341 | // There is no challenge info, since the identity in URL worked. |
| 6342 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6343 | |
| 6344 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6345 | |
| 6346 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 6347 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6348 | } |
| 6349 | |
| 6350 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 6351 | // incorrect identity in the URL. The identity from the URL should be used only |
| 6352 | // once. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6353 | TEST_P(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6354 | HttpRequestInfo request; |
| 6355 | request.method = "GET"; |
| 6356 | // Note: the URL has a username:password in it. The password "baz" is |
| 6357 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6358 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6359 | |
| 6360 | request.load_flags = LOAD_NORMAL; |
| 6361 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6362 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6363 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6364 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6365 | |
| 6366 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6367 | MockWrite( |
| 6368 | "GET / HTTP/1.1\r\n" |
| 6369 | "Host: www.example.org\r\n" |
| 6370 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6371 | }; |
| 6372 | |
| 6373 | MockRead data_reads1[] = { |
| 6374 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6375 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6376 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6377 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6378 | }; |
| 6379 | |
| 6380 | // After the challenge above, the transaction will be restarted using the |
| 6381 | // identity from the url (foo, baz) to answer the challenge. |
| 6382 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6383 | MockWrite( |
| 6384 | "GET / HTTP/1.1\r\n" |
| 6385 | "Host: www.example.org\r\n" |
| 6386 | "Connection: keep-alive\r\n" |
| 6387 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6388 | }; |
| 6389 | |
| 6390 | MockRead data_reads2[] = { |
| 6391 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6392 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6393 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6394 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6395 | }; |
| 6396 | |
| 6397 | // After the challenge above, the transaction will be restarted using the |
| 6398 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 6399 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6400 | MockWrite( |
| 6401 | "GET / HTTP/1.1\r\n" |
| 6402 | "Host: www.example.org\r\n" |
| 6403 | "Connection: keep-alive\r\n" |
| 6404 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6405 | }; |
| 6406 | |
| 6407 | MockRead data_reads3[] = { |
| 6408 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6409 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6410 | MockRead(SYNCHRONOUS, OK), |
| 6411 | }; |
| 6412 | |
| 6413 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6414 | data_writes1, arraysize(data_writes1)); |
| 6415 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6416 | data_writes2, arraysize(data_writes2)); |
| 6417 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6418 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6419 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6420 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6421 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6422 | |
| 6423 | TestCompletionCallback callback1; |
| 6424 | |
| 6425 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 6426 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6427 | |
| 6428 | rv = callback1.WaitForResult(); |
| 6429 | EXPECT_EQ(OK, rv); |
| 6430 | |
| 6431 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 6432 | TestCompletionCallback callback2; |
| 6433 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 6434 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6435 | rv = callback2.WaitForResult(); |
| 6436 | EXPECT_EQ(OK, rv); |
| 6437 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6438 | |
| 6439 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6440 | ASSERT_TRUE(response != NULL); |
| 6441 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 6442 | |
| 6443 | TestCompletionCallback callback3; |
| 6444 | rv = trans->RestartWithAuth( |
| 6445 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 6446 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6447 | rv = callback3.WaitForResult(); |
| 6448 | EXPECT_EQ(OK, rv); |
| 6449 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6450 | |
| 6451 | response = trans->GetResponseInfo(); |
| 6452 | ASSERT_TRUE(response != NULL); |
| 6453 | |
| 6454 | // There is no challenge info, since the identity worked. |
| 6455 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6456 | |
| 6457 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6458 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6459 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 6460 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6461 | } |
| 6462 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6463 | |
| 6464 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 6465 | // correct identity in the URL, but its use is being suppressed. The identity |
| 6466 | // from the URL should never be used. |
| 6467 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
| 6468 | HttpRequestInfo request; |
| 6469 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6470 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6471 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 6472 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6473 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6474 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6475 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6476 | |
| 6477 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6478 | MockWrite( |
| 6479 | "GET / HTTP/1.1\r\n" |
| 6480 | "Host: www.example.org\r\n" |
| 6481 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6482 | }; |
| 6483 | |
| 6484 | MockRead data_reads1[] = { |
| 6485 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6486 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6487 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6488 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6489 | }; |
| 6490 | |
| 6491 | // After the challenge above, the transaction will be restarted using the |
| 6492 | // identity supplied by the user, not the one in the URL, to answer the |
| 6493 | // challenge. |
| 6494 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6495 | MockWrite( |
| 6496 | "GET / HTTP/1.1\r\n" |
| 6497 | "Host: www.example.org\r\n" |
| 6498 | "Connection: keep-alive\r\n" |
| 6499 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6500 | }; |
| 6501 | |
| 6502 | MockRead data_reads3[] = { |
| 6503 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6504 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6505 | MockRead(SYNCHRONOUS, OK), |
| 6506 | }; |
| 6507 | |
| 6508 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6509 | data_writes1, arraysize(data_writes1)); |
| 6510 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6511 | data_writes3, arraysize(data_writes3)); |
| 6512 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6513 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 6514 | |
| 6515 | TestCompletionCallback callback1; |
| 6516 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 6517 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6518 | rv = callback1.WaitForResult(); |
| 6519 | EXPECT_EQ(OK, rv); |
| 6520 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6521 | |
| 6522 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6523 | ASSERT_TRUE(response != NULL); |
| 6524 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 6525 | |
| 6526 | TestCompletionCallback callback3; |
| 6527 | rv = trans->RestartWithAuth( |
| 6528 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 6529 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6530 | rv = callback3.WaitForResult(); |
| 6531 | EXPECT_EQ(OK, rv); |
| 6532 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6533 | |
| 6534 | response = trans->GetResponseInfo(); |
| 6535 | ASSERT_TRUE(response != NULL); |
| 6536 | |
| 6537 | // There is no challenge info, since the identity worked. |
| 6538 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6539 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6540 | |
| 6541 | // Empty the current queue. |
| 6542 | base::MessageLoop::current()->RunUntilIdle(); |
| 6543 | } |
| 6544 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6545 | // Test that previously tried username/passwords for a realm get re-used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6546 | TEST_P(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6547 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6548 | |
| 6549 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 6550 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6551 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6552 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6553 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6554 | request.load_flags = 0; |
| 6555 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6556 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6557 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6558 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6559 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6560 | MockWrite( |
| 6561 | "GET /x/y/z HTTP/1.1\r\n" |
| 6562 | "Host: www.example.org\r\n" |
| 6563 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6564 | }; |
| 6565 | |
| 6566 | MockRead data_reads1[] = { |
| 6567 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6568 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6569 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6570 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6571 | }; |
| 6572 | |
| 6573 | // Resend with authorization (username=foo, password=bar) |
| 6574 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6575 | MockWrite( |
| 6576 | "GET /x/y/z HTTP/1.1\r\n" |
| 6577 | "Host: www.example.org\r\n" |
| 6578 | "Connection: keep-alive\r\n" |
| 6579 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6580 | }; |
| 6581 | |
| 6582 | // Sever accepts the authorization. |
| 6583 | MockRead data_reads2[] = { |
| 6584 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6585 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6586 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6587 | }; |
| 6588 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6589 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6590 | data_writes1, arraysize(data_writes1)); |
| 6591 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6592 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6593 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6594 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6595 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6596 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6597 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6598 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6599 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6600 | |
| 6601 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6602 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6603 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6604 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6605 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6606 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6607 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6608 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6609 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6610 | rv = trans->RestartWithAuth( |
| 6611 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6612 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6613 | |
| 6614 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6615 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6616 | |
| 6617 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6618 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6619 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6620 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6621 | } |
| 6622 | |
| 6623 | // ------------------------------------------------------------------------ |
| 6624 | |
| 6625 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 6626 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6627 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6628 | request.method = "GET"; |
| 6629 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 6630 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6631 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6632 | request.load_flags = 0; |
| 6633 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6634 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6635 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6636 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6637 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6638 | MockWrite( |
| 6639 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 6640 | "Host: www.example.org\r\n" |
| 6641 | "Connection: keep-alive\r\n" |
| 6642 | // Send preemptive authorization for MyRealm1 |
| 6643 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6644 | }; |
| 6645 | |
| 6646 | // The server didn't like the preemptive authorization, and |
| 6647 | // challenges us for a different realm (MyRealm2). |
| 6648 | MockRead data_reads1[] = { |
| 6649 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6650 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 6651 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6652 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6653 | }; |
| 6654 | |
| 6655 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 6656 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6657 | MockWrite( |
| 6658 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 6659 | "Host: www.example.org\r\n" |
| 6660 | "Connection: keep-alive\r\n" |
| 6661 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6662 | }; |
| 6663 | |
| 6664 | // Sever accepts the authorization. |
| 6665 | MockRead data_reads2[] = { |
| 6666 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6667 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6668 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6669 | }; |
| 6670 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6671 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6672 | data_writes1, arraysize(data_writes1)); |
| 6673 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6674 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6675 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6676 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6677 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6678 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6679 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6680 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6681 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6682 | |
| 6683 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6684 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6685 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6686 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6687 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6688 | ASSERT_TRUE(response->auth_challenge.get()); |
| 6689 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6690 | EXPECT_EQ("www.example.org:80", |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6691 | response->auth_challenge->challenger.ToString()); |
| 6692 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 6693 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6694 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6695 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6696 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6697 | rv = trans->RestartWithAuth( |
| 6698 | AuthCredentials(kFoo2, kBar2), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6699 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6700 | |
| 6701 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6702 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6703 | |
| 6704 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6705 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6706 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6707 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6708 | } |
| 6709 | |
| 6710 | // ------------------------------------------------------------------------ |
| 6711 | |
| 6712 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 6713 | // succeed with preemptive authorization. |
| 6714 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6715 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6716 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6717 | request.url = GURL("http://www.example.org/x/y/z2"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6718 | request.load_flags = 0; |
| 6719 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6720 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6721 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6722 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6723 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6724 | MockWrite( |
| 6725 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 6726 | "Host: www.example.org\r\n" |
| 6727 | "Connection: keep-alive\r\n" |
| 6728 | // The authorization for MyRealm1 gets sent preemptively |
| 6729 | // (since the url is in the same protection space) |
| 6730 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6731 | }; |
| 6732 | |
| 6733 | // Sever accepts the preemptive authorization |
| 6734 | MockRead data_reads1[] = { |
| 6735 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6736 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6737 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6738 | }; |
| 6739 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6740 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6741 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6742 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6743 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6744 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6745 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6746 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6747 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6748 | |
| 6749 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6750 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6751 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6752 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6753 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6754 | |
| 6755 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6756 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6757 | } |
| 6758 | |
| 6759 | // ------------------------------------------------------------------------ |
| 6760 | |
| 6761 | // Transaction 4: request another URL in MyRealm (however the |
| 6762 | // url is not known to belong to the protection space, so no pre-auth). |
| 6763 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6764 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6765 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6766 | request.url = GURL("http://www.example.org/x/1"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6767 | request.load_flags = 0; |
| 6768 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6769 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6770 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6771 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6772 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6773 | MockWrite( |
| 6774 | "GET /x/1 HTTP/1.1\r\n" |
| 6775 | "Host: www.example.org\r\n" |
| 6776 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6777 | }; |
| 6778 | |
| 6779 | MockRead data_reads1[] = { |
| 6780 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6781 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6782 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6783 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6784 | }; |
| 6785 | |
| 6786 | // Resend with authorization from MyRealm's cache. |
| 6787 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6788 | MockWrite( |
| 6789 | "GET /x/1 HTTP/1.1\r\n" |
| 6790 | "Host: www.example.org\r\n" |
| 6791 | "Connection: keep-alive\r\n" |
| 6792 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6793 | }; |
| 6794 | |
| 6795 | // Sever accepts the authorization. |
| 6796 | MockRead data_reads2[] = { |
| 6797 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6798 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6799 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6800 | }; |
| 6801 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6802 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6803 | data_writes1, arraysize(data_writes1)); |
| 6804 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6805 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6806 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6807 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6808 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6809 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6810 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6811 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6812 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6813 | |
| 6814 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6815 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6816 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6817 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6818 | TestCompletionCallback callback2; |
| 6819 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6820 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6821 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6822 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6823 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6824 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6825 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6826 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6827 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6828 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6829 | } |
| 6830 | |
| 6831 | // ------------------------------------------------------------------------ |
| 6832 | |
| 6833 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 6834 | // cached identity. Should invalidate and re-prompt. |
| 6835 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6836 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6837 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6838 | request.url = GURL("http://www.example.org/p/q/t"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6839 | request.load_flags = 0; |
| 6840 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6841 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6842 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6843 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6844 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6845 | MockWrite( |
| 6846 | "GET /p/q/t HTTP/1.1\r\n" |
| 6847 | "Host: www.example.org\r\n" |
| 6848 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6849 | }; |
| 6850 | |
| 6851 | MockRead data_reads1[] = { |
| 6852 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6853 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6854 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6855 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6856 | }; |
| 6857 | |
| 6858 | // Resend with authorization from cache for MyRealm. |
| 6859 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6860 | MockWrite( |
| 6861 | "GET /p/q/t HTTP/1.1\r\n" |
| 6862 | "Host: www.example.org\r\n" |
| 6863 | "Connection: keep-alive\r\n" |
| 6864 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6865 | }; |
| 6866 | |
| 6867 | // Sever rejects the authorization. |
| 6868 | MockRead data_reads2[] = { |
| 6869 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6870 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6871 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6872 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6873 | }; |
| 6874 | |
| 6875 | // At this point we should prompt for new credentials for MyRealm. |
| 6876 | // Restart with username=foo3, password=foo4. |
| 6877 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6878 | MockWrite( |
| 6879 | "GET /p/q/t HTTP/1.1\r\n" |
| 6880 | "Host: www.example.org\r\n" |
| 6881 | "Connection: keep-alive\r\n" |
| 6882 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6883 | }; |
| 6884 | |
| 6885 | // Sever accepts the authorization. |
| 6886 | MockRead data_reads3[] = { |
| 6887 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6888 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6889 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6890 | }; |
| 6891 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6892 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6893 | data_writes1, arraysize(data_writes1)); |
| 6894 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6895 | data_writes2, arraysize(data_writes2)); |
| 6896 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6897 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6898 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6899 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6900 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6901 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6902 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6903 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6904 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6905 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6906 | |
| 6907 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6908 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6909 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6910 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6911 | TestCompletionCallback callback2; |
| 6912 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6913 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6914 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6915 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6916 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6917 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6918 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6919 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6920 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6921 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6922 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6923 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6924 | rv = trans->RestartWithAuth( |
| 6925 | AuthCredentials(kFoo3, kBar3), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6926 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6927 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6928 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6929 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6930 | |
| 6931 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6932 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6933 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6934 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6935 | } |
| 6936 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6937 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6938 | // Tests that nonce count increments when multiple auth attempts |
| 6939 | // are started with the same nonce. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6940 | TEST_P(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 6941 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 6942 | new HttpAuthHandlerDigest::Factory(); |
| 6943 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 6944 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 6945 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6946 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6947 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6948 | |
| 6949 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 6950 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6951 | HttpRequestInfo request; |
| 6952 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6953 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6954 | request.load_flags = 0; |
| 6955 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6956 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6957 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6958 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6959 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6960 | MockWrite( |
| 6961 | "GET /x/y/z HTTP/1.1\r\n" |
| 6962 | "Host: www.example.org\r\n" |
| 6963 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6964 | }; |
| 6965 | |
| 6966 | MockRead data_reads1[] = { |
| 6967 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6968 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 6969 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6970 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6971 | }; |
| 6972 | |
| 6973 | // Resend with authorization (username=foo, password=bar) |
| 6974 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6975 | MockWrite( |
| 6976 | "GET /x/y/z HTTP/1.1\r\n" |
| 6977 | "Host: www.example.org\r\n" |
| 6978 | "Connection: keep-alive\r\n" |
| 6979 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 6980 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 6981 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 6982 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6983 | }; |
| 6984 | |
| 6985 | // Sever accepts the authorization. |
| 6986 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 6987 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6988 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6989 | }; |
| 6990 | |
| 6991 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6992 | data_writes1, arraysize(data_writes1)); |
| 6993 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6994 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6995 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6996 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6997 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6998 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6999 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7000 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7001 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7002 | |
| 7003 | rv = callback1.WaitForResult(); |
| 7004 | EXPECT_EQ(OK, rv); |
| 7005 | |
| 7006 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7007 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7008 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7009 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7010 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7011 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7012 | rv = trans->RestartWithAuth( |
| 7013 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7014 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7015 | |
| 7016 | rv = callback2.WaitForResult(); |
| 7017 | EXPECT_EQ(OK, rv); |
| 7018 | |
| 7019 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7020 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7021 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 7022 | } |
| 7023 | |
| 7024 | // ------------------------------------------------------------------------ |
| 7025 | |
| 7026 | // Transaction 2: Request another resource in digestive's protection space. |
| 7027 | // This will preemptively add an Authorization header which should have an |
| 7028 | // "nc" value of 2 (as compared to 1 in the first use. |
| 7029 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7030 | HttpRequestInfo request; |
| 7031 | request.method = "GET"; |
| 7032 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7033 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7034 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7035 | request.load_flags = 0; |
| 7036 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7037 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7038 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7039 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7040 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7041 | MockWrite( |
| 7042 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7043 | "Host: www.example.org\r\n" |
| 7044 | "Connection: keep-alive\r\n" |
| 7045 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 7046 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 7047 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 7048 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7049 | }; |
| 7050 | |
| 7051 | // Sever accepts the authorization. |
| 7052 | MockRead data_reads1[] = { |
| 7053 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7054 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7055 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7056 | }; |
| 7057 | |
| 7058 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7059 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7060 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7061 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7062 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7063 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7064 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7065 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7066 | |
| 7067 | rv = callback1.WaitForResult(); |
| 7068 | EXPECT_EQ(OK, rv); |
| 7069 | |
| 7070 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7071 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7072 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 7073 | } |
| 7074 | } |
| 7075 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7076 | // Test the ResetStateForRestart() private method. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7077 | TEST_P(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7078 | // Create a transaction (the dependencies aren't important). |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7079 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 7080 | scoped_ptr<HttpNetworkTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7081 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7082 | |
| 7083 | // Setup some state (which we expect ResetStateForRestart() will clear). |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7084 | trans->read_buf_ = new IOBuffer(15); |
| 7085 | trans->read_buf_len_ = 15; |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 7086 | trans->request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7087 | |
| 7088 | // Setup state in response_ |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 7089 | HttpResponseInfo* response = &trans->response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7090 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7091 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7092 | response->response_time = base::Time::Now(); |
| 7093 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7094 | |
| 7095 | { // Setup state for response_.vary_data |
| 7096 | HttpRequestInfo request; |
| 7097 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 7098 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 7099 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7100 | request.extra_headers.SetHeader("Foo", "1"); |
| 7101 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7102 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7103 | } |
| 7104 | |
| 7105 | // Cause the above state to be reset. |
| 7106 | trans->ResetStateForRestart(); |
| 7107 | |
| 7108 | // Verify that the state that needed to be reset, has been reset. |
[email protected] | 9b6fee1 | 2009-09-29 18:13:07 | [diff] [blame] | 7109 | EXPECT_TRUE(trans->read_buf_.get() == NULL); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7110 | EXPECT_EQ(0, trans->read_buf_len_); |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 7111 | EXPECT_TRUE(trans->request_headers_.IsEmpty()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7112 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 7113 | EXPECT_TRUE(response->headers.get() == NULL); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 7114 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7115 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7116 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7117 | } |
| 7118 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7119 | // Test HTTPS connections to a site with a bad certificate |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7120 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7121 | HttpRequestInfo request; |
| 7122 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7123 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7124 | request.load_flags = 0; |
| 7125 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7126 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7127 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7128 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7129 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7130 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7131 | MockWrite( |
| 7132 | "GET / HTTP/1.1\r\n" |
| 7133 | "Host: www.example.org\r\n" |
| 7134 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7135 | }; |
| 7136 | |
| 7137 | MockRead data_reads[] = { |
| 7138 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7139 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7140 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7141 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7142 | }; |
| 7143 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 7144 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7145 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7146 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7147 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7148 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7149 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7150 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7151 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7152 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7153 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7154 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7155 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7156 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7157 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7158 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7159 | |
| 7160 | rv = callback.WaitForResult(); |
| 7161 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 7162 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7163 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7164 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7165 | |
| 7166 | rv = callback.WaitForResult(); |
| 7167 | EXPECT_EQ(OK, rv); |
| 7168 | |
| 7169 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7170 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7171 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7172 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7173 | } |
| 7174 | |
| 7175 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 7176 | // proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7177 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7178 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7179 | |
| 7180 | HttpRequestInfo request; |
| 7181 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7182 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7183 | request.load_flags = 0; |
| 7184 | |
| 7185 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7186 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7187 | "Host: www.example.org:443\r\n" |
| 7188 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7189 | }; |
| 7190 | |
| 7191 | MockRead proxy_reads[] = { |
| 7192 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7193 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7194 | }; |
| 7195 | |
| 7196 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7197 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7198 | "Host: www.example.org:443\r\n" |
| 7199 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7200 | MockWrite("GET / HTTP/1.1\r\n" |
| 7201 | "Host: www.example.org\r\n" |
| 7202 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7203 | }; |
| 7204 | |
| 7205 | MockRead data_reads[] = { |
| 7206 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7207 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7208 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7209 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7210 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7211 | }; |
| 7212 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7213 | StaticSocketDataProvider ssl_bad_certificate( |
| 7214 | proxy_reads, arraysize(proxy_reads), |
| 7215 | proxy_writes, arraysize(proxy_writes)); |
| 7216 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7217 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7218 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7219 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7220 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7221 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7222 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7223 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7224 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7225 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7226 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7227 | |
| 7228 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7229 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7230 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7231 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 7232 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7233 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7234 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7235 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7236 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7237 | |
| 7238 | rv = callback.WaitForResult(); |
| 7239 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 7240 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7241 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7242 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7243 | |
| 7244 | rv = callback.WaitForResult(); |
| 7245 | EXPECT_EQ(OK, rv); |
| 7246 | |
| 7247 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7248 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7249 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7250 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7251 | } |
| 7252 | } |
| 7253 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7254 | |
| 7255 | // Test HTTPS connections to a site, going through an HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7256 | TEST_P(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7257 | session_deps_.proxy_service = |
| 7258 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7259 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7260 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7261 | |
| 7262 | HttpRequestInfo request; |
| 7263 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7264 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7265 | request.load_flags = 0; |
| 7266 | |
| 7267 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7268 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7269 | "Host: www.example.org:443\r\n" |
| 7270 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7271 | MockWrite("GET / HTTP/1.1\r\n" |
| 7272 | "Host: www.example.org\r\n" |
| 7273 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7274 | }; |
| 7275 | |
| 7276 | MockRead data_reads[] = { |
| 7277 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7278 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7279 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7280 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7281 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7282 | }; |
| 7283 | |
| 7284 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7285 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7286 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 7287 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7288 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7289 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7290 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 7291 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7292 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7293 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7294 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7295 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7296 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7297 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7298 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7299 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7300 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7301 | |
| 7302 | rv = callback.WaitForResult(); |
| 7303 | EXPECT_EQ(OK, rv); |
| 7304 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7305 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7306 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7307 | |
| 7308 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7309 | EXPECT_EQ(200, response->headers->response_code()); |
| 7310 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7311 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7312 | |
| 7313 | LoadTimingInfo load_timing_info; |
| 7314 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7315 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7316 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7317 | } |
| 7318 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7319 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7320 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7321 | session_deps_.proxy_service = |
| 7322 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7323 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7324 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7325 | |
| 7326 | HttpRequestInfo request; |
| 7327 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7328 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7329 | request.load_flags = 0; |
| 7330 | |
| 7331 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7332 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7333 | "Host: www.example.org:443\r\n" |
| 7334 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7335 | }; |
| 7336 | |
| 7337 | MockRead data_reads[] = { |
| 7338 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 7339 | MockRead("Location: http://login.example.com/\r\n"), |
| 7340 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7341 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7342 | }; |
| 7343 | |
| 7344 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7345 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7346 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7347 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7348 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7349 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7350 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7351 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7352 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7353 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7354 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7355 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7356 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7357 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7358 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7359 | |
| 7360 | rv = callback.WaitForResult(); |
| 7361 | EXPECT_EQ(OK, rv); |
| 7362 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7363 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7364 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7365 | |
| 7366 | EXPECT_EQ(302, response->headers->response_code()); |
| 7367 | std::string url; |
| 7368 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7369 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7370 | |
| 7371 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 7372 | // timing for the proxy connection instead of the connection to the host, |
| 7373 | // and no send / receive times. |
| 7374 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 7375 | LoadTimingInfo load_timing_info; |
| 7376 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7377 | |
| 7378 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 7379 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7380 | |
| 7381 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 7382 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 7383 | load_timing_info.proxy_resolve_end); |
| 7384 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 7385 | load_timing_info.connect_timing.connect_start); |
| 7386 | ExpectConnectTimingHasTimes( |
| 7387 | load_timing_info.connect_timing, |
| 7388 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7389 | |
| 7390 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 7391 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 7392 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7393 | } |
| 7394 | |
| 7395 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7396 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7397 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7398 | |
| 7399 | HttpRequestInfo request; |
| 7400 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7401 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7402 | request.load_flags = 0; |
| 7403 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 7404 | scoped_ptr<SpdySerializedFrame> conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7405 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 7406 | scoped_ptr<SpdySerializedFrame> goaway( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7407 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7408 | MockWrite data_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7409 | CreateMockWrite(*conn.get(), 0, SYNCHRONOUS), |
| 7410 | CreateMockWrite(*goaway.get(), 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7411 | }; |
| 7412 | |
| 7413 | static const char* const kExtraHeaders[] = { |
| 7414 | "location", |
| 7415 | "http://login.example.com/", |
| 7416 | }; |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 7417 | scoped_ptr<SpdySerializedFrame> resp(spdy_util_.ConstructSpdySynReplyError( |
| 7418 | "302 Redirect", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7419 | MockRead data_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7420 | CreateMockRead(*resp.get(), 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7421 | }; |
| 7422 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7423 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7424 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7425 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7426 | proxy_ssl.SetNextProto(GetProtocol()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7427 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7428 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7429 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7430 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7431 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7432 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7433 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7434 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7435 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7436 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7437 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7438 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7439 | |
| 7440 | rv = callback.WaitForResult(); |
| 7441 | EXPECT_EQ(OK, rv); |
| 7442 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7443 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7444 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7445 | |
| 7446 | EXPECT_EQ(302, response->headers->response_code()); |
| 7447 | std::string url; |
| 7448 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7449 | EXPECT_EQ("http://login.example.com/", url); |
| 7450 | } |
| 7451 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7452 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7453 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7454 | ErrorResponseToHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7455 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7456 | |
| 7457 | HttpRequestInfo request; |
| 7458 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7459 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7460 | request.load_flags = 0; |
| 7461 | |
| 7462 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7463 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7464 | "Host: www.example.org:443\r\n" |
| 7465 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7466 | }; |
| 7467 | |
| 7468 | MockRead data_reads[] = { |
| 7469 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 7470 | MockRead("Content-Length: 23\r\n\r\n"), |
| 7471 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7472 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7473 | }; |
| 7474 | |
| 7475 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7476 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7477 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7478 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7479 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7480 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7481 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7482 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7483 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7484 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7485 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7486 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7487 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7488 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7489 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7490 | |
| 7491 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7492 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7493 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7494 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7495 | } |
| 7496 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7497 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7498 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7499 | ErrorResponseToHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7500 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7501 | |
| 7502 | HttpRequestInfo request; |
| 7503 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7504 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7505 | request.load_flags = 0; |
| 7506 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 7507 | scoped_ptr<SpdySerializedFrame> conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7508 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 7509 | scoped_ptr<SpdySerializedFrame> rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7510 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7511 | MockWrite data_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7512 | CreateMockWrite(*conn.get(), 0), CreateMockWrite(*rst.get(), 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7513 | }; |
| 7514 | |
| 7515 | static const char* const kExtraHeaders[] = { |
| 7516 | "location", |
| 7517 | "http://login.example.com/", |
| 7518 | }; |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 7519 | scoped_ptr<SpdySerializedFrame> resp(spdy_util_.ConstructSpdySynReplyError( |
| 7520 | "404 Not Found", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
| 7521 | scoped_ptr<SpdySerializedFrame> body(spdy_util_.ConstructSpdyBodyFrame( |
| 7522 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7523 | MockRead data_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7524 | CreateMockRead(*resp.get(), 1), |
| 7525 | CreateMockRead(*body.get(), 2), |
| 7526 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7527 | }; |
| 7528 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7529 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7530 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7531 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7532 | proxy_ssl.SetNextProto(GetProtocol()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7533 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7534 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7535 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7536 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7537 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7538 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7539 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7540 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7541 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7542 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7543 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7544 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7545 | |
| 7546 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7547 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7548 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7549 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7550 | } |
| 7551 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7552 | // Test the request-challenge-retry sequence for basic auth, through |
| 7553 | // a SPDY proxy over a single SPDY session. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7554 | TEST_P(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7555 | HttpRequestInfo request; |
| 7556 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7557 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7558 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 7559 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7560 | |
| 7561 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7562 | session_deps_.proxy_service = |
| 7563 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7564 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7565 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7566 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7567 | |
| 7568 | // Since we have proxy, should try to establish tunnel. |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 7569 | scoped_ptr<SpdySerializedFrame> req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7570 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 7571 | scoped_ptr<SpdySerializedFrame> rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7572 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7573 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7574 | |
| 7575 | // After calling trans->RestartWithAuth(), this is the request we should |
| 7576 | // be issuing -- the final header line contains the credentials. |
| 7577 | const char* const kAuthCredentials[] = { |
| 7578 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 7579 | }; |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 7580 | scoped_ptr<SpdySerializedFrame> connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 7581 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7582 | HostPortPair("www.example.org", 443))); |
| 7583 | // fetch https://www.example.org/ via HTTP |
| 7584 | const char get[] = |
| 7585 | "GET / HTTP/1.1\r\n" |
| 7586 | "Host: www.example.org\r\n" |
| 7587 | "Connection: keep-alive\r\n\r\n"; |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 7588 | scoped_ptr<SpdySerializedFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7589 | spdy_util_.ConstructSpdyBodyFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7590 | |
| 7591 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7592 | CreateMockWrite(*req, 0, ASYNC), |
| 7593 | CreateMockWrite(*rst, 2, ASYNC), |
| 7594 | CreateMockWrite(*connect2, 3), |
| 7595 | CreateMockWrite(*wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7596 | }; |
| 7597 | |
| 7598 | // The proxy responds to the connect with a 407, using a persistent |
| 7599 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 7600 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7601 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7602 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 7603 | }; |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 7604 | scoped_ptr<SpdySerializedFrame> conn_auth_resp( |
| 7605 | spdy_util_.ConstructSpdySynReplyError(kAuthStatus, kAuthChallenge, |
| 7606 | arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7607 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 7608 | scoped_ptr<SpdySerializedFrame> conn_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7609 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7610 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 7611 | "Content-Length: 5\r\n\r\n"; |
| 7612 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 7613 | scoped_ptr<SpdySerializedFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7614 | spdy_util_.ConstructSpdyBodyFrame(3, resp, strlen(resp), false)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 7615 | scoped_ptr<SpdySerializedFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7616 | spdy_util_.ConstructSpdyBodyFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7617 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7618 | CreateMockRead(*conn_auth_resp, 1, ASYNC), |
| 7619 | CreateMockRead(*conn_resp, 4, ASYNC), |
| 7620 | CreateMockRead(*wrapped_get_resp, 6, ASYNC), |
| 7621 | CreateMockRead(*wrapped_body, 7, ASYNC), |
| 7622 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7623 | }; |
| 7624 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7625 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7626 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7627 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7628 | // Negotiate SPDY to the proxy |
| 7629 | SSLSocketDataProvider proxy(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7630 | proxy.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7631 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7632 | // Vanilla SSL to the server |
| 7633 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7634 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7635 | |
| 7636 | TestCompletionCallback callback1; |
| 7637 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7638 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7639 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7640 | |
| 7641 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 7642 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7643 | |
| 7644 | rv = callback1.WaitForResult(); |
| 7645 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 7646 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7647 | log.GetEntries(&entries); |
| 7648 | size_t pos = ExpectLogContainsSomewhere( |
| 7649 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 7650 | NetLog::PHASE_NONE); |
| 7651 | ExpectLogContainsSomewhere( |
| 7652 | entries, pos, |
| 7653 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 7654 | NetLog::PHASE_NONE); |
| 7655 | |
| 7656 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7657 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7658 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7659 | EXPECT_EQ(407, response->headers->response_code()); |
| 7660 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7661 | EXPECT_TRUE(response->auth_challenge.get() != NULL); |
| 7662 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 7663 | |
| 7664 | TestCompletionCallback callback2; |
| 7665 | |
| 7666 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7667 | callback2.callback()); |
| 7668 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7669 | |
| 7670 | rv = callback2.WaitForResult(); |
| 7671 | EXPECT_EQ(OK, rv); |
| 7672 | |
| 7673 | response = trans->GetResponseInfo(); |
| 7674 | ASSERT_TRUE(response != NULL); |
| 7675 | |
| 7676 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7677 | EXPECT_EQ(200, response->headers->response_code()); |
| 7678 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 7679 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7680 | |
| 7681 | // The password prompt info should not be set. |
| 7682 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 7683 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7684 | LoadTimingInfo load_timing_info; |
| 7685 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7686 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7687 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7688 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7689 | trans.reset(); |
| 7690 | session->CloseAllConnections(); |
| 7691 | } |
| 7692 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7693 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 7694 | // origin that is different from that of its associated resource. |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 7695 | TEST_P(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
| 7696 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
| 7697 | scoped_ptr<TestProxyDelegate> proxy_delegate(new TestProxyDelegate()); |
| 7698 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 7699 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7700 | HttpRequestInfo request; |
| 7701 | HttpRequestInfo push_request; |
| 7702 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7703 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7704 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7705 | push_request.method = "GET"; |
| 7706 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 7707 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 7708 | // Configure against https proxy server "myproxy:443". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7709 | session_deps_.proxy_service = |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 7710 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7711 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7712 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7713 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 7714 | session_deps_.proxy_delegate.reset(proxy_delegate.release()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7715 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7716 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7717 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 7718 | scoped_ptr<SpdySerializedFrame> stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 7719 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, false)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7720 | |
| 7721 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7722 | CreateMockWrite(*stream1_syn, 0, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7723 | }; |
| 7724 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 7725 | scoped_ptr<SpdySerializedFrame> stream1_reply( |
| 7726 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7727 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 7728 | scoped_ptr<SpdySerializedFrame> stream1_body( |
| 7729 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7730 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 7731 | scoped_ptr<SpdySerializedFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 7732 | NULL, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7733 | const char kPushedData[] = "pushed"; |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 7734 | scoped_ptr<SpdySerializedFrame> stream2_body( |
| 7735 | spdy_util_.ConstructSpdyBodyFrame(2, kPushedData, strlen(kPushedData), |
| 7736 | true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7737 | |
| 7738 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7739 | CreateMockRead(*stream1_reply, 1, ASYNC), |
| 7740 | CreateMockRead(*stream2_syn, 2, ASYNC), |
| 7741 | CreateMockRead(*stream1_body, 3, ASYNC), |
| 7742 | CreateMockRead(*stream2_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 7743 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7744 | }; |
| 7745 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7746 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7747 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7748 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7749 | // Negotiate SPDY to the proxy |
| 7750 | SSLSocketDataProvider proxy(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7751 | proxy.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7752 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7753 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7754 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7755 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7756 | TestCompletionCallback callback; |
| 7757 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 7758 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7759 | |
| 7760 | rv = callback.WaitForResult(); |
| 7761 | EXPECT_EQ(OK, rv); |
| 7762 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7763 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7764 | scoped_ptr<HttpTransaction> push_trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7765 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 7766 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7767 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7768 | |
| 7769 | rv = callback.WaitForResult(); |
| 7770 | EXPECT_EQ(OK, rv); |
| 7771 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 7772 | |
| 7773 | ASSERT_TRUE(response != NULL); |
| 7774 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7775 | |
| 7776 | EXPECT_EQ(200, response->headers->response_code()); |
| 7777 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7778 | |
| 7779 | std::string response_data; |
| 7780 | rv = ReadTransaction(trans.get(), &response_data); |
| 7781 | EXPECT_EQ(OK, rv); |
| 7782 | EXPECT_EQ("hello!", response_data); |
| 7783 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7784 | LoadTimingInfo load_timing_info; |
| 7785 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7786 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7787 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7788 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7789 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7790 | EXPECT_TRUE(push_response->headers.get() != NULL); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7791 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 7792 | |
| 7793 | rv = ReadTransaction(push_trans.get(), &response_data); |
| 7794 | EXPECT_EQ(OK, rv); |
| 7795 | EXPECT_EQ("pushed", response_data); |
| 7796 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7797 | LoadTimingInfo push_load_timing_info; |
| 7798 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 7799 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 7800 | // The transactions should share a socket ID, despite being for different |
| 7801 | // origins. |
| 7802 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 7803 | push_load_timing_info.socket_log_id); |
| 7804 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7805 | trans.reset(); |
| 7806 | push_trans.reset(); |
| 7807 | session->CloseAllConnections(); |
| 7808 | } |
| 7809 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7810 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7811 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 7812 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
| 7813 | scoped_ptr<TestProxyDelegate> proxy_delegate(new TestProxyDelegate()); |
| 7814 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 7815 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7816 | HttpRequestInfo request; |
| 7817 | |
| 7818 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7819 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7820 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 7821 | session_deps_.proxy_service = |
| 7822 | ProxyService::CreateFixed("https://myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7823 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7824 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7825 | |
| 7826 | // Enable cross-origin push. |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 7827 | session_deps_.proxy_delegate.reset(proxy_delegate.release()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7828 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7829 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7830 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 7831 | scoped_ptr<SpdySerializedFrame> stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 7832 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, false)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7833 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 7834 | scoped_ptr<SpdySerializedFrame> push_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7835 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7836 | |
| 7837 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7838 | CreateMockWrite(*stream1_syn, 0, ASYNC), CreateMockWrite(*push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7839 | }; |
| 7840 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 7841 | scoped_ptr<SpdySerializedFrame> stream1_reply( |
| 7842 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7843 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 7844 | scoped_ptr<SpdySerializedFrame> stream1_body( |
| 7845 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7846 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 7847 | scoped_ptr<SpdySerializedFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 7848 | NULL, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7849 | |
| 7850 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7851 | CreateMockRead(*stream1_reply, 1, ASYNC), |
| 7852 | CreateMockRead(*stream2_syn, 2, ASYNC), |
| 7853 | CreateMockRead(*stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 7854 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7855 | }; |
| 7856 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7857 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7858 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7859 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7860 | // Negotiate SPDY to the proxy |
| 7861 | SSLSocketDataProvider proxy(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7862 | proxy.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7863 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7864 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7865 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7866 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7867 | TestCompletionCallback callback; |
| 7868 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 7869 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7870 | |
| 7871 | rv = callback.WaitForResult(); |
| 7872 | EXPECT_EQ(OK, rv); |
| 7873 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7874 | |
| 7875 | ASSERT_TRUE(response != NULL); |
| 7876 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7877 | |
| 7878 | EXPECT_EQ(200, response->headers->response_code()); |
| 7879 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7880 | |
| 7881 | std::string response_data; |
| 7882 | rv = ReadTransaction(trans.get(), &response_data); |
| 7883 | EXPECT_EQ(OK, rv); |
| 7884 | EXPECT_EQ("hello!", response_data); |
| 7885 | |
| 7886 | trans.reset(); |
| 7887 | session->CloseAllConnections(); |
| 7888 | } |
| 7889 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 7890 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 7891 | // resources. |
| 7892 | TEST_P(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 7893 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
| 7894 | scoped_ptr<TestProxyDelegate> proxy_delegate(new TestProxyDelegate()); |
| 7895 | proxy_delegate->set_trusted_spdy_proxy( |
| 7896 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 7897 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 7898 | HttpRequestInfo request; |
| 7899 | |
| 7900 | request.method = "GET"; |
| 7901 | request.url = GURL("http://www.example.org/"); |
| 7902 | |
| 7903 | // Configure against https proxy server "myproxy:70". |
| 7904 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
| 7905 | BoundTestNetLog log; |
| 7906 | session_deps_.net_log = log.bound().net_log(); |
| 7907 | |
| 7908 | // Enable cross-origin push. |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 7909 | session_deps_.proxy_delegate.reset(proxy_delegate.release()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 7910 | |
| 7911 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7912 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 7913 | scoped_ptr<SpdySerializedFrame> stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 7914 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, false)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 7915 | |
| 7916 | MockWrite spdy_writes[] = { |
| 7917 | CreateMockWrite(*stream1_syn, 0, ASYNC), |
| 7918 | }; |
| 7919 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 7920 | scoped_ptr<SpdySerializedFrame> stream1_reply( |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 7921 | spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
| 7922 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 7923 | scoped_ptr<SpdySerializedFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 7924 | nullptr, 0, 2, 1, "https://myproxy:70/foo.dat")); |
| 7925 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 7926 | scoped_ptr<SpdySerializedFrame> stream1_body( |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 7927 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 7928 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 7929 | scoped_ptr<SpdySerializedFrame> stream2_reply( |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 7930 | spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
| 7931 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 7932 | scoped_ptr<SpdySerializedFrame> stream2_body( |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 7933 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 7934 | |
| 7935 | MockRead spdy_reads[] = { |
| 7936 | CreateMockRead(*stream1_reply, 1, ASYNC), |
| 7937 | CreateMockRead(*stream2_syn, 2, ASYNC), |
| 7938 | CreateMockRead(*stream1_body, 3, ASYNC), |
| 7939 | CreateMockRead(*stream2_body, 4, ASYNC), |
| 7940 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
| 7941 | }; |
| 7942 | |
| 7943 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7944 | arraysize(spdy_writes)); |
| 7945 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 7946 | // Negotiate SPDY to the proxy |
| 7947 | SSLSocketDataProvider proxy(ASYNC, OK); |
| 7948 | proxy.SetNextProto(GetProtocol()); |
| 7949 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 7950 | |
| 7951 | scoped_ptr<HttpTransaction> trans( |
| 7952 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 7953 | TestCompletionCallback callback; |
| 7954 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 7955 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7956 | |
| 7957 | rv = callback.WaitForResult(); |
| 7958 | EXPECT_EQ(OK, rv); |
| 7959 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7960 | |
| 7961 | ASSERT_TRUE(response != nullptr); |
| 7962 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7963 | |
| 7964 | EXPECT_EQ(200, response->headers->response_code()); |
| 7965 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7966 | |
| 7967 | std::string response_data; |
| 7968 | rv = ReadTransaction(trans.get(), &response_data); |
| 7969 | EXPECT_EQ(OK, rv); |
| 7970 | EXPECT_EQ("hello!", response_data); |
| 7971 | |
| 7972 | trans.reset(); |
| 7973 | session->CloseAllConnections(); |
| 7974 | } |
| 7975 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7976 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 7977 | // HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7978 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7979 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7980 | |
| 7981 | HttpRequestInfo request; |
| 7982 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7983 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7984 | request.load_flags = 0; |
| 7985 | |
| 7986 | // Attempt to fetch the URL from a server with a bad cert |
| 7987 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7988 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7989 | "Host: www.example.org:443\r\n" |
| 7990 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7991 | }; |
| 7992 | |
| 7993 | MockRead bad_cert_reads[] = { |
| 7994 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7995 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7996 | }; |
| 7997 | |
| 7998 | // Attempt to fetch the URL with a good cert |
| 7999 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8000 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8001 | "Host: www.example.org:443\r\n" |
| 8002 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8003 | MockWrite("GET / HTTP/1.1\r\n" |
| 8004 | "Host: www.example.org\r\n" |
| 8005 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8006 | }; |
| 8007 | |
| 8008 | MockRead good_cert_reads[] = { |
| 8009 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8010 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8011 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8012 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8013 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8014 | }; |
| 8015 | |
| 8016 | StaticSocketDataProvider ssl_bad_certificate( |
| 8017 | bad_cert_reads, arraysize(bad_cert_reads), |
| 8018 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 8019 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 8020 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8021 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8022 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8023 | |
| 8024 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8025 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8026 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8027 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8028 | |
| 8029 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8030 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8031 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8032 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8033 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8034 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8035 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8036 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8037 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8038 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [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] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8041 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8042 | |
| 8043 | rv = callback.WaitForResult(); |
| 8044 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 8045 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8046 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8047 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8048 | |
| 8049 | rv = callback.WaitForResult(); |
| 8050 | EXPECT_EQ(OK, rv); |
| 8051 | |
| 8052 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8053 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8054 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8055 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8056 | } |
| 8057 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8058 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8059 | HttpRequestInfo request; |
| 8060 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8061 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8062 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8063 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8064 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8065 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8066 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8067 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8068 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8069 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8070 | MockWrite( |
| 8071 | "GET / HTTP/1.1\r\n" |
| 8072 | "Host: www.example.org\r\n" |
| 8073 | "Connection: keep-alive\r\n" |
| 8074 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8075 | }; |
| 8076 | |
| 8077 | // Lastly, the server responds with the actual content. |
| 8078 | MockRead data_reads[] = { |
| 8079 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8080 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8081 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8082 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8083 | }; |
| 8084 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8085 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8086 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8087 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8088 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8089 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8090 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8091 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8092 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8093 | |
| 8094 | rv = callback.WaitForResult(); |
| 8095 | EXPECT_EQ(OK, rv); |
| 8096 | } |
| 8097 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8098 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8099 | HttpRequestInfo request; |
| 8100 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8101 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8102 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8103 | "Chromium Ultra Awesome X Edition"); |
| 8104 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8105 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8106 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8107 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8108 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8109 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8110 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8111 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8112 | "Host: www.example.org:443\r\n" |
| 8113 | "Proxy-Connection: keep-alive\r\n" |
| 8114 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8115 | }; |
| 8116 | MockRead data_reads[] = { |
| 8117 | // Return an error, so the transaction stops here (this test isn't |
| 8118 | // interested in the rest). |
| 8119 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 8120 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8121 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 8122 | }; |
| 8123 | |
| 8124 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8125 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8126 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8127 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8128 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8129 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8130 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8131 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8132 | |
| 8133 | rv = callback.WaitForResult(); |
| 8134 | EXPECT_EQ(OK, rv); |
| 8135 | } |
| 8136 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8137 | TEST_P(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8138 | HttpRequestInfo request; |
| 8139 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8140 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8141 | request.load_flags = 0; |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 8142 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 8143 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8144 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8145 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8146 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8147 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8148 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8149 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8150 | MockWrite( |
| 8151 | "GET / HTTP/1.1\r\n" |
| 8152 | "Host: www.example.org\r\n" |
| 8153 | "Connection: keep-alive\r\n" |
| 8154 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8155 | }; |
| 8156 | |
| 8157 | // Lastly, the server responds with the actual content. |
| 8158 | MockRead data_reads[] = { |
| 8159 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8160 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8161 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8162 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8163 | }; |
| 8164 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8165 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8166 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8167 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8168 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8169 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8170 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8171 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8172 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8173 | |
| 8174 | rv = callback.WaitForResult(); |
| 8175 | EXPECT_EQ(OK, rv); |
| 8176 | } |
| 8177 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8178 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8179 | HttpRequestInfo request; |
| 8180 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8181 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8182 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8183 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8184 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8185 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8186 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8187 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8188 | MockWrite( |
| 8189 | "POST / HTTP/1.1\r\n" |
| 8190 | "Host: www.example.org\r\n" |
| 8191 | "Connection: keep-alive\r\n" |
| 8192 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8193 | }; |
| 8194 | |
| 8195 | // Lastly, the server responds with the actual content. |
| 8196 | MockRead data_reads[] = { |
| 8197 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8198 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8199 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8200 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8201 | }; |
| 8202 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8203 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8204 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8205 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8206 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8207 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8208 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8209 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8210 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8211 | |
| 8212 | rv = callback.WaitForResult(); |
| 8213 | EXPECT_EQ(OK, rv); |
| 8214 | } |
| 8215 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8216 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8217 | HttpRequestInfo request; |
| 8218 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8219 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8220 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8221 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8222 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8223 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8224 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8225 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8226 | MockWrite( |
| 8227 | "PUT / HTTP/1.1\r\n" |
| 8228 | "Host: www.example.org\r\n" |
| 8229 | "Connection: keep-alive\r\n" |
| 8230 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8231 | }; |
| 8232 | |
| 8233 | // Lastly, the server responds with the actual content. |
| 8234 | MockRead data_reads[] = { |
| 8235 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8236 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8237 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8238 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8239 | }; |
| 8240 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8241 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8242 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8243 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8244 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8245 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8246 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8247 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8248 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8249 | |
| 8250 | rv = callback.WaitForResult(); |
| 8251 | EXPECT_EQ(OK, rv); |
| 8252 | } |
| 8253 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8254 | TEST_P(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8255 | HttpRequestInfo request; |
| 8256 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8257 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8258 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8259 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8260 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8261 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8262 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8263 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 8264 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 8265 | "Host: www.example.org\r\n" |
| 8266 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8267 | }; |
| 8268 | |
| 8269 | // Lastly, the server responds with the actual content. |
| 8270 | MockRead data_reads[] = { |
| 8271 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8272 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8273 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8274 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8275 | }; |
| 8276 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8277 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8278 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8279 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8280 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8281 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8282 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8283 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8284 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8285 | |
| 8286 | rv = callback.WaitForResult(); |
| 8287 | EXPECT_EQ(OK, rv); |
| 8288 | } |
| 8289 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8290 | TEST_P(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8291 | HttpRequestInfo request; |
| 8292 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8293 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8294 | request.load_flags = LOAD_BYPASS_CACHE; |
| 8295 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8296 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8297 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8298 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8299 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8300 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8301 | MockWrite( |
| 8302 | "GET / HTTP/1.1\r\n" |
| 8303 | "Host: www.example.org\r\n" |
| 8304 | "Connection: keep-alive\r\n" |
| 8305 | "Pragma: no-cache\r\n" |
| 8306 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8307 | }; |
| 8308 | |
| 8309 | // Lastly, the server responds with the actual content. |
| 8310 | MockRead data_reads[] = { |
| 8311 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8312 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8313 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8314 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8315 | }; |
| 8316 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8317 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8318 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8319 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8320 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8321 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8322 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8323 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8324 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8325 | |
| 8326 | rv = callback.WaitForResult(); |
| 8327 | EXPECT_EQ(OK, rv); |
| 8328 | } |
| 8329 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8330 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8331 | BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8332 | HttpRequestInfo request; |
| 8333 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8334 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8335 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 8336 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8337 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8338 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8339 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8340 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8341 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8342 | MockWrite( |
| 8343 | "GET / HTTP/1.1\r\n" |
| 8344 | "Host: www.example.org\r\n" |
| 8345 | "Connection: keep-alive\r\n" |
| 8346 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8347 | }; |
| 8348 | |
| 8349 | // Lastly, the server responds with the actual content. |
| 8350 | MockRead data_reads[] = { |
| 8351 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8352 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8353 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8354 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8355 | }; |
| 8356 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8357 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8358 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8359 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8360 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8361 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8362 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8363 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8364 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8365 | |
| 8366 | rv = callback.WaitForResult(); |
| 8367 | EXPECT_EQ(OK, rv); |
| 8368 | } |
| 8369 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8370 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8371 | HttpRequestInfo request; |
| 8372 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8373 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8374 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8375 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8376 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8377 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8378 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8379 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8380 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8381 | MockWrite( |
| 8382 | "GET / HTTP/1.1\r\n" |
| 8383 | "Host: www.example.org\r\n" |
| 8384 | "Connection: keep-alive\r\n" |
| 8385 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8386 | }; |
| 8387 | |
| 8388 | // Lastly, the server responds with the actual content. |
| 8389 | MockRead data_reads[] = { |
| 8390 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8391 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8392 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8393 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8394 | }; |
| 8395 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8396 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8397 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8398 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8399 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8400 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8401 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8402 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8403 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8404 | |
| 8405 | rv = callback.WaitForResult(); |
| 8406 | EXPECT_EQ(OK, rv); |
| 8407 | } |
| 8408 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8409 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8410 | HttpRequestInfo request; |
| 8411 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8412 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8413 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 8414 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 8415 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8416 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8417 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8418 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8419 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8420 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8421 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8422 | MockWrite( |
| 8423 | "GET / HTTP/1.1\r\n" |
| 8424 | "Host: www.example.org\r\n" |
| 8425 | "Connection: keep-alive\r\n" |
| 8426 | "referer: www.foo.com\r\n" |
| 8427 | "hEllo: Kitty\r\n" |
| 8428 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8429 | }; |
| 8430 | |
| 8431 | // Lastly, the server responds with the actual content. |
| 8432 | MockRead data_reads[] = { |
| 8433 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8434 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8435 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8436 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8437 | }; |
| 8438 | |
| 8439 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8440 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8441 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8442 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8443 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8444 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8445 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8446 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8447 | |
| 8448 | rv = callback.WaitForResult(); |
| 8449 | EXPECT_EQ(OK, rv); |
| 8450 | } |
| 8451 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8452 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8453 | HttpRequestInfo request; |
| 8454 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8455 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8456 | request.load_flags = 0; |
| 8457 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8458 | session_deps_.proxy_service = |
| 8459 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8460 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8461 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8462 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8463 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8464 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8465 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8466 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8467 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 8468 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8469 | |
| 8470 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8471 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 8472 | MockWrite( |
| 8473 | "GET / HTTP/1.1\r\n" |
| 8474 | "Host: www.example.org\r\n" |
| 8475 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8476 | |
| 8477 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8478 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8479 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8480 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8481 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8482 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8483 | }; |
| 8484 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8485 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8486 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8487 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8488 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8489 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8490 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8491 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8492 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8493 | |
| 8494 | rv = callback.WaitForResult(); |
| 8495 | EXPECT_EQ(OK, rv); |
| 8496 | |
| 8497 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8498 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8499 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8500 | LoadTimingInfo load_timing_info; |
| 8501 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8502 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8503 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8504 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8505 | std::string response_text; |
| 8506 | rv = ReadTransaction(trans.get(), &response_text); |
| 8507 | EXPECT_EQ(OK, rv); |
| 8508 | EXPECT_EQ("Payload", response_text); |
| 8509 | } |
| 8510 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8511 | TEST_P(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8512 | HttpRequestInfo request; |
| 8513 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8514 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8515 | request.load_flags = 0; |
| 8516 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8517 | session_deps_.proxy_service = |
| 8518 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8519 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8520 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8521 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8522 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8523 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8524 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8525 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8526 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 8527 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8528 | |
| 8529 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8530 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 8531 | arraysize(write_buffer)), |
| 8532 | MockWrite( |
| 8533 | "GET / HTTP/1.1\r\n" |
| 8534 | "Host: www.example.org\r\n" |
| 8535 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8536 | |
| 8537 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8538 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 8539 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8540 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8541 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8542 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8543 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8544 | }; |
| 8545 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8546 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8547 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8548 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8549 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8550 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8551 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8552 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8553 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8554 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8555 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8556 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8557 | |
| 8558 | rv = callback.WaitForResult(); |
| 8559 | EXPECT_EQ(OK, rv); |
| 8560 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8561 | LoadTimingInfo load_timing_info; |
| 8562 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8563 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8564 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8565 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8566 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8567 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8568 | |
| 8569 | std::string response_text; |
| 8570 | rv = ReadTransaction(trans.get(), &response_text); |
| 8571 | EXPECT_EQ(OK, rv); |
| 8572 | EXPECT_EQ("Payload", response_text); |
| 8573 | } |
| 8574 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8575 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8576 | HttpRequestInfo request; |
| 8577 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8578 | request.url = GURL("http://www.example.org/"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8579 | request.load_flags = 0; |
| 8580 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8581 | session_deps_.proxy_service = |
| 8582 | ProxyService::CreateFixed("socks4://myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8583 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8584 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8585 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8586 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8587 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8588 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8589 | |
| 8590 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 8591 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8592 | |
| 8593 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8594 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 8595 | MockWrite( |
| 8596 | "GET / HTTP/1.1\r\n" |
| 8597 | "Host: www.example.org\r\n" |
| 8598 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8599 | |
| 8600 | MockRead data_reads[] = { |
| 8601 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 8602 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8603 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8604 | MockRead("Payload"), |
| 8605 | MockRead(SYNCHRONOUS, OK) |
| 8606 | }; |
| 8607 | |
| 8608 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8609 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8610 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8611 | |
| 8612 | TestCompletionCallback callback; |
| 8613 | |
| 8614 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8615 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8616 | |
| 8617 | rv = callback.WaitForResult(); |
| 8618 | EXPECT_EQ(OK, rv); |
| 8619 | |
| 8620 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8621 | ASSERT_TRUE(response != NULL); |
| 8622 | |
| 8623 | LoadTimingInfo load_timing_info; |
| 8624 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8625 | TestLoadTimingNotReused(load_timing_info, |
| 8626 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8627 | |
| 8628 | std::string response_text; |
| 8629 | rv = ReadTransaction(trans.get(), &response_text); |
| 8630 | EXPECT_EQ(OK, rv); |
| 8631 | EXPECT_EQ("Payload", response_text); |
| 8632 | } |
| 8633 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8634 | TEST_P(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8635 | HttpRequestInfo request; |
| 8636 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8637 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8638 | request.load_flags = 0; |
| 8639 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8640 | session_deps_.proxy_service = |
| 8641 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8642 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8643 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8644 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8645 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8646 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8647 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8648 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8649 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 8650 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8651 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8652 | 0x05, // Version |
| 8653 | 0x01, // Command (CONNECT) |
| 8654 | 0x00, // Reserved. |
| 8655 | 0x03, // Address type (DOMAINNAME). |
| 8656 | 0x0F, // Length of domain (15) |
| 8657 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 8658 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8659 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8660 | const char kSOCKS5OkResponse[] = |
| 8661 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 8662 | |
| 8663 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8664 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 8665 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 8666 | MockWrite( |
| 8667 | "GET / HTTP/1.1\r\n" |
| 8668 | "Host: www.example.org\r\n" |
| 8669 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8670 | |
| 8671 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8672 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 8673 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8674 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8675 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8676 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8677 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8678 | }; |
| 8679 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8680 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8681 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8682 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8683 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8684 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8685 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8686 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8687 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8688 | |
| 8689 | rv = callback.WaitForResult(); |
| 8690 | EXPECT_EQ(OK, rv); |
| 8691 | |
| 8692 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8693 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8694 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8695 | LoadTimingInfo load_timing_info; |
| 8696 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8697 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8698 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8699 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8700 | std::string response_text; |
| 8701 | rv = ReadTransaction(trans.get(), &response_text); |
| 8702 | EXPECT_EQ(OK, rv); |
| 8703 | EXPECT_EQ("Payload", response_text); |
| 8704 | } |
| 8705 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8706 | TEST_P(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8707 | HttpRequestInfo request; |
| 8708 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8709 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8710 | request.load_flags = 0; |
| 8711 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8712 | session_deps_.proxy_service = |
| 8713 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8714 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8715 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8716 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8717 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8718 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8719 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8720 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8721 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 8722 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8723 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8724 | 0x05, // Version |
| 8725 | 0x01, // Command (CONNECT) |
| 8726 | 0x00, // Reserved. |
| 8727 | 0x03, // Address type (DOMAINNAME). |
| 8728 | 0x0F, // Length of domain (15) |
| 8729 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 8730 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8731 | }; |
| 8732 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8733 | const char kSOCKS5OkResponse[] = |
| 8734 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 8735 | |
| 8736 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8737 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 8738 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 8739 | arraysize(kSOCKS5OkRequest)), |
| 8740 | MockWrite( |
| 8741 | "GET / HTTP/1.1\r\n" |
| 8742 | "Host: www.example.org\r\n" |
| 8743 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8744 | |
| 8745 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8746 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 8747 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8748 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8749 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8750 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8751 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8752 | }; |
| 8753 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8754 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8755 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8756 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8757 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8758 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8759 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8760 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8761 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8762 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8763 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8764 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8765 | |
| 8766 | rv = callback.WaitForResult(); |
| 8767 | EXPECT_EQ(OK, rv); |
| 8768 | |
| 8769 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8770 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8771 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8772 | LoadTimingInfo load_timing_info; |
| 8773 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8774 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8775 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8776 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8777 | std::string response_text; |
| 8778 | rv = ReadTransaction(trans.get(), &response_text); |
| 8779 | EXPECT_EQ(OK, rv); |
| 8780 | EXPECT_EQ("Payload", response_text); |
| 8781 | } |
| 8782 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8783 | namespace { |
| 8784 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8785 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8786 | |
| 8787 | struct GroupNameTest { |
| 8788 | std::string proxy_server; |
| 8789 | std::string url; |
| 8790 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8791 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8792 | }; |
| 8793 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8794 | scoped_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8795 | NextProto next_proto, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8796 | SpdySessionDependencies* session_deps_) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8797 | scoped_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8798 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8799 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8800 | session->http_server_properties(); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 8801 | AlternativeService alternative_service( |
bnc | 4988e43 | 2015-03-31 03:06:25 | [diff] [blame] | 8802 | AlternateProtocolFromNextProto(next_proto), "", 443); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 8803 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 8804 | http_server_properties->SetAlternativeService( |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 8805 | HostPortPair("host.with.alternate", 80), alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8806 | |
| 8807 | return session; |
| 8808 | } |
| 8809 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8810 | int GroupNameTransactionHelper(const std::string& url, |
| 8811 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8812 | HttpRequestInfo request; |
| 8813 | request.method = "GET"; |
| 8814 | request.url = GURL(url); |
| 8815 | request.load_flags = 0; |
| 8816 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8817 | scoped_ptr<HttpTransaction> trans( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8818 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8819 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8820 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8821 | |
| 8822 | // We do not complete this request, the dtor will clean the transaction up. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8823 | return trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8824 | } |
| 8825 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8826 | } // namespace |
| 8827 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8828 | TEST_P(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8829 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8830 | { |
| 8831 | "", // unused |
| 8832 | "http://www.example.org/direct", |
| 8833 | "www.example.org:80", |
| 8834 | false, |
| 8835 | }, |
| 8836 | { |
| 8837 | "", // unused |
| 8838 | "http://[2001:1418:13:1::25]/direct", |
| 8839 | "[2001:1418:13:1::25]:80", |
| 8840 | false, |
| 8841 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8842 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8843 | // SSL Tests |
| 8844 | { |
| 8845 | "", // unused |
| 8846 | "https://www.example.org/direct_ssl", |
| 8847 | "ssl/www.example.org:443", |
| 8848 | true, |
| 8849 | }, |
| 8850 | { |
| 8851 | "", // unused |
| 8852 | "https://[2001:1418:13:1::25]/direct", |
| 8853 | "ssl/[2001:1418:13:1::25]:443", |
| 8854 | true, |
| 8855 | }, |
| 8856 | { |
| 8857 | "", // unused |
| 8858 | "http://host.with.alternate/direct", |
| 8859 | "ssl/host.with.alternate:443", |
| 8860 | true, |
| 8861 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8862 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8863 | |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 8864 | session_deps_.parse_alternative_services = true; |
| 8865 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8866 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8867 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8868 | session_deps_.proxy_service = |
| 8869 | ProxyService::CreateFixed(tests[i].proxy_server); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8870 | scoped_ptr<HttpNetworkSession> session( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8871 | SetupSessionForGroupNameTests(GetProtocol(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8872 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8873 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 8874 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
| 8875 | new CaptureGroupNameTransportSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8876 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8877 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8878 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8879 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8880 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 8881 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 8882 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8883 | |
| 8884 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8885 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8886 | if (tests[i].ssl) |
| 8887 | EXPECT_EQ(tests[i].expected_group_name, |
| 8888 | ssl_conn_pool->last_group_name_received()); |
| 8889 | else |
| 8890 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 8891 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8892 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8893 | } |
| 8894 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8895 | TEST_P(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8896 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8897 | { |
| 8898 | "http_proxy", |
| 8899 | "http://www.example.org/http_proxy_normal", |
| 8900 | "www.example.org:80", |
| 8901 | false, |
| 8902 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8903 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8904 | // SSL Tests |
| 8905 | { |
| 8906 | "http_proxy", |
| 8907 | "https://www.example.org/http_connect_ssl", |
| 8908 | "ssl/www.example.org:443", |
| 8909 | true, |
| 8910 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 8911 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8912 | { |
| 8913 | "http_proxy", |
| 8914 | "http://host.with.alternate/direct", |
| 8915 | "ssl/host.with.alternate:443", |
| 8916 | true, |
| 8917 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 8918 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8919 | { |
| 8920 | "http_proxy", |
| 8921 | "ftp://ftp.google.com/http_proxy_normal", |
| 8922 | "ftp/ftp.google.com:21", |
| 8923 | false, |
| 8924 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8925 | }; |
| 8926 | |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 8927 | session_deps_.parse_alternative_services = true; |
| 8928 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8929 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8930 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8931 | session_deps_.proxy_service = |
| 8932 | ProxyService::CreateFixed(tests[i].proxy_server); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8933 | scoped_ptr<HttpNetworkSession> session( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8934 | SetupSessionForGroupNameTests(GetProtocol(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8935 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8936 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8937 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8938 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8939 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8940 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8941 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8942 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8943 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8944 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8945 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8946 | mock_pool_manager->SetSocketPoolForHTTPProxy(proxy_host, http_proxy_pool); |
| 8947 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 8948 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8949 | |
| 8950 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8951 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8952 | if (tests[i].ssl) |
| 8953 | EXPECT_EQ(tests[i].expected_group_name, |
| 8954 | ssl_conn_pool->last_group_name_received()); |
| 8955 | else |
| 8956 | EXPECT_EQ(tests[i].expected_group_name, |
| 8957 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8958 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8959 | } |
| 8960 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8961 | TEST_P(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8962 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8963 | { |
| 8964 | "socks4://socks_proxy:1080", |
| 8965 | "http://www.example.org/socks4_direct", |
| 8966 | "socks4/www.example.org:80", |
| 8967 | false, |
| 8968 | }, |
| 8969 | { |
| 8970 | "socks5://socks_proxy:1080", |
| 8971 | "http://www.example.org/socks5_direct", |
| 8972 | "socks5/www.example.org:80", |
| 8973 | false, |
| 8974 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8975 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8976 | // SSL Tests |
| 8977 | { |
| 8978 | "socks4://socks_proxy:1080", |
| 8979 | "https://www.example.org/socks4_ssl", |
| 8980 | "socks4/ssl/www.example.org:443", |
| 8981 | true, |
| 8982 | }, |
| 8983 | { |
| 8984 | "socks5://socks_proxy:1080", |
| 8985 | "https://www.example.org/socks5_ssl", |
| 8986 | "socks5/ssl/www.example.org:443", |
| 8987 | true, |
| 8988 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 8989 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8990 | { |
| 8991 | "socks4://socks_proxy:1080", |
| 8992 | "http://host.with.alternate/direct", |
| 8993 | "socks4/ssl/host.with.alternate:443", |
| 8994 | true, |
| 8995 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8996 | }; |
| 8997 | |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 8998 | session_deps_.parse_alternative_services = true; |
| 8999 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9000 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9001 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9002 | session_deps_.proxy_service = |
| 9003 | ProxyService::CreateFixed(tests[i].proxy_server); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9004 | scoped_ptr<HttpNetworkSession> session( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9005 | SetupSessionForGroupNameTests(GetProtocol(), &session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 9006 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9007 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9008 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9009 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9010 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9011 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9012 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9013 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9014 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 9015 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 9016 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9017 | mock_pool_manager->SetSocketPoolForSOCKSProxy(proxy_host, socks_conn_pool); |
| 9018 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9019 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9020 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9021 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9022 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9023 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9024 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9025 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9026 | if (tests[i].ssl) |
| 9027 | EXPECT_EQ(tests[i].expected_group_name, |
| 9028 | ssl_conn_pool->last_group_name_received()); |
| 9029 | else |
| 9030 | EXPECT_EQ(tests[i].expected_group_name, |
| 9031 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9032 | } |
| 9033 | } |
| 9034 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9035 | TEST_P(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9036 | HttpRequestInfo request; |
| 9037 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9038 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9039 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9040 | session_deps_.proxy_service = |
| 9041 | ProxyService::CreateFixed("myproxy:70;foobar:80"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9042 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 9043 | // This simulates failure resolving all hostnames; that means we will fail |
| 9044 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9045 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9046 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9047 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9048 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9049 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9050 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9051 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9052 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9053 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9054 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9055 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9056 | rv = callback.WaitForResult(); |
[email protected] | f7fccee | 2010-09-16 20:53:01 | [diff] [blame] | 9057 | EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9058 | } |
| 9059 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9060 | // Base test to make sure that when the load flags for a request specify to |
| 9061 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9062 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9063 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9064 | // Issue a request, asking to bypass the cache(s). |
| 9065 | HttpRequestInfo request; |
| 9066 | request.method = "GET"; |
| 9067 | request.load_flags = load_flags; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9068 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9069 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 9070 | // Select a host resolver that does caching. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9071 | session_deps_.host_resolver.reset(new MockCachingHostResolver); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9072 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9073 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 9074 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9075 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9076 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9077 | // 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] | 9078 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 9079 | TestCompletionCallback callback; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9080 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9081 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
| 9082 | DEFAULT_PRIORITY, &addrlist, callback.callback(), NULL, BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 9083 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9084 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9085 | EXPECT_EQ(OK, rv); |
| 9086 | |
| 9087 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 9088 | // and confirming it completes synchronously. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9089 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9090 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
| 9091 | DEFAULT_PRIORITY, &addrlist, callback.callback(), NULL, BoundNetLog()); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9092 | ASSERT_EQ(OK, rv); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9093 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9094 | // 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] | 9095 | // we can tell if the next lookup hit the cache, or the "network". |
| 9096 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9097 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9098 | |
| 9099 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 9100 | // 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] | 9101 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9102 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9103 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9104 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9105 | // Run the request. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9106 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9107 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9108 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9109 | |
| 9110 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9111 | // "www.example.org". |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9112 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
| 9113 | } |
| 9114 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9115 | // There are multiple load flags that should trigger the host cache bypass. |
| 9116 | // Test each in isolation: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9117 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9118 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 9119 | } |
| 9120 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9121 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9122 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 9123 | } |
| 9124 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9125 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9126 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 9127 | } |
| 9128 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9129 | // Make sure we can handle an error when writing the request. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9130 | TEST_P(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9131 | HttpRequestInfo request; |
| 9132 | request.method = "GET"; |
| 9133 | request.url = GURL("http://www.foo.com/"); |
| 9134 | request.load_flags = 0; |
| 9135 | |
| 9136 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9137 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9138 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9139 | StaticSocketDataProvider data(NULL, 0, |
| 9140 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9141 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9142 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9143 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9144 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9145 | |
| 9146 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9147 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9148 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9149 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9150 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9151 | |
| 9152 | rv = callback.WaitForResult(); |
| 9153 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9154 | |
| 9155 | IPEndPoint endpoint; |
| 9156 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 9157 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9158 | } |
| 9159 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9160 | // Check that a connection closed after the start of the headers finishes ok. |
| 9161 | TEST_P(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9162 | HttpRequestInfo request; |
| 9163 | request.method = "GET"; |
| 9164 | request.url = GURL("http://www.foo.com/"); |
| 9165 | request.load_flags = 0; |
| 9166 | |
| 9167 | MockRead data_reads[] = { |
| 9168 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9169 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9170 | }; |
| 9171 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9172 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9173 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9174 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9175 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9176 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9177 | |
| 9178 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9179 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9180 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9181 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9182 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9183 | |
| 9184 | rv = callback.WaitForResult(); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9185 | EXPECT_EQ(OK, rv); |
| 9186 | |
| 9187 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9188 | ASSERT_TRUE(response != NULL); |
| 9189 | |
| 9190 | EXPECT_TRUE(response->headers.get() != NULL); |
| 9191 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9192 | |
| 9193 | std::string response_data; |
| 9194 | rv = ReadTransaction(trans.get(), &response_data); |
| 9195 | EXPECT_EQ(OK, rv); |
| 9196 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9197 | |
| 9198 | IPEndPoint endpoint; |
| 9199 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 9200 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9201 | } |
| 9202 | |
| 9203 | // Make sure that a dropped connection while draining the body for auth |
| 9204 | // restart does the right thing. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9205 | TEST_P(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9206 | HttpRequestInfo request; |
| 9207 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9208 | request.url = GURL("http://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9209 | request.load_flags = 0; |
| 9210 | |
| 9211 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9212 | MockWrite( |
| 9213 | "GET / HTTP/1.1\r\n" |
| 9214 | "Host: www.example.org\r\n" |
| 9215 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9216 | }; |
| 9217 | |
| 9218 | MockRead data_reads1[] = { |
| 9219 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 9220 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9221 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9222 | MockRead("Content-Length: 14\r\n\r\n"), |
| 9223 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9224 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9225 | }; |
| 9226 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9227 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9228 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9229 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9230 | |
| 9231 | // After calling trans->RestartWithAuth(), this is the request we should |
| 9232 | // be issuing -- the final header line contains the credentials. |
| 9233 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9234 | MockWrite( |
| 9235 | "GET / HTTP/1.1\r\n" |
| 9236 | "Host: www.example.org\r\n" |
| 9237 | "Connection: keep-alive\r\n" |
| 9238 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9239 | }; |
| 9240 | |
| 9241 | // Lastly, the server responds with the actual content. |
| 9242 | MockRead data_reads2[] = { |
| 9243 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9244 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9245 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9246 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9247 | }; |
| 9248 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9249 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9250 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9251 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9252 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9253 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9254 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9255 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9256 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9257 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9258 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9259 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9260 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9261 | |
| 9262 | rv = callback1.WaitForResult(); |
| 9263 | EXPECT_EQ(OK, rv); |
| 9264 | |
| 9265 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9266 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9267 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9268 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9269 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9270 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9271 | rv = trans->RestartWithAuth( |
| 9272 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9273 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9274 | |
| 9275 | rv = callback2.WaitForResult(); |
| 9276 | EXPECT_EQ(OK, rv); |
| 9277 | |
| 9278 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9279 | ASSERT_TRUE(response != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9280 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 9281 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9282 | } |
| 9283 | |
| 9284 | // Test HTTPS connections going through a proxy that sends extra data. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9285 | TEST_P(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9286 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9287 | |
| 9288 | HttpRequestInfo request; |
| 9289 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9290 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9291 | request.load_flags = 0; |
| 9292 | |
| 9293 | MockRead proxy_reads[] = { |
| 9294 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9295 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9296 | }; |
| 9297 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9298 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9299 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9300 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9301 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9302 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9303 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9304 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9305 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9306 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9307 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9308 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9309 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9310 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9311 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9312 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9313 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9314 | |
| 9315 | rv = callback.WaitForResult(); |
| 9316 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 9317 | } |
| 9318 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9319 | TEST_P(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9320 | HttpRequestInfo request; |
| 9321 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9322 | request.url = GURL("http://www.example.org/"); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9323 | request.load_flags = 0; |
| 9324 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9325 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9326 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9327 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9328 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9329 | MockRead data_reads[] = { |
| 9330 | 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] | 9331 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9332 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9333 | |
| 9334 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9335 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9336 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9337 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9338 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9339 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9340 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9341 | |
| 9342 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9343 | |
| 9344 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9345 | ASSERT_TRUE(response != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9346 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9347 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9348 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9349 | |
| 9350 | std::string response_data; |
| 9351 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 5543cbb | 2012-04-20 16:35:23 | [diff] [blame] | 9352 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9353 | } |
| 9354 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9355 | TEST_P(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9356 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9357 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9358 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 9359 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 9360 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9361 | |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9362 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 9363 | element_readers.push_back(make_scoped_ptr(new UploadFileElementReader( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9364 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
| 9365 | std::numeric_limits<uint64_t>::max(), base::Time()))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9366 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9367 | |
| 9368 | HttpRequestInfo request; |
| 9369 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9370 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9371 | request.upload_data_stream = &upload_data_stream; |
| 9372 | request.load_flags = 0; |
| 9373 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9374 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9375 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9376 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9377 | |
| 9378 | MockRead data_reads[] = { |
| 9379 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 9380 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9381 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9382 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9383 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9384 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9385 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9386 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9387 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9388 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9389 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9390 | |
| 9391 | rv = callback.WaitForResult(); |
| 9392 | EXPECT_EQ(OK, rv); |
| 9393 | |
| 9394 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9395 | ASSERT_TRUE(response != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9396 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9397 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9398 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9399 | |
| 9400 | std::string response_data; |
| 9401 | rv = ReadTransaction(trans.get(), &response_data); |
| 9402 | EXPECT_EQ(OK, rv); |
| 9403 | EXPECT_EQ("hello world", response_data); |
| 9404 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9405 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9406 | } |
| 9407 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9408 | TEST_P(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9409 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9410 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9411 | std::string temp_file_content("Unreadable file."); |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 9412 | ASSERT_TRUE(base::WriteFile(temp_file, temp_file_content.c_str(), |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9413 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 9414 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9415 | |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9416 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9417 | element_readers.push_back(make_scoped_ptr(new UploadFileElementReader( |
| 9418 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
| 9419 | std::numeric_limits<uint64_t>::max(), base::Time()))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9420 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9421 | |
| 9422 | HttpRequestInfo request; |
| 9423 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9424 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9425 | request.upload_data_stream = &upload_data_stream; |
| 9426 | request.load_flags = 0; |
| 9427 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9428 | // If we try to upload an unreadable file, the transaction should fail. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9429 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9430 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9431 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9432 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9433 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9434 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9435 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9436 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9437 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9438 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9439 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9440 | |
| 9441 | rv = callback.WaitForResult(); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9442 | EXPECT_EQ(ERR_ACCESS_DENIED, rv); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9443 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9444 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9445 | } |
| 9446 | |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9447 | TEST_P(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
| 9448 | class FakeUploadElementReader : public UploadElementReader { |
| 9449 | public: |
| 9450 | FakeUploadElementReader() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9451 | ~FakeUploadElementReader() override {} |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9452 | |
| 9453 | const CompletionCallback& callback() const { return callback_; } |
| 9454 | |
| 9455 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9456 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9457 | callback_ = callback; |
| 9458 | return ERR_IO_PENDING; |
| 9459 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9460 | uint64_t GetContentLength() const override { return 0; } |
| 9461 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9462 | int Read(IOBuffer* buf, |
| 9463 | int buf_length, |
| 9464 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9465 | return ERR_FAILED; |
| 9466 | } |
| 9467 | |
| 9468 | private: |
| 9469 | CompletionCallback callback_; |
| 9470 | }; |
| 9471 | |
| 9472 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9473 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 9474 | element_readers.push_back(make_scoped_ptr(fake_reader)); |
| 9475 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9476 | |
| 9477 | HttpRequestInfo request; |
| 9478 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9479 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9480 | request.upload_data_stream = &upload_data_stream; |
| 9481 | request.load_flags = 0; |
| 9482 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9483 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9484 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9485 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9486 | |
| 9487 | StaticSocketDataProvider data; |
| 9488 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9489 | |
| 9490 | TestCompletionCallback callback; |
| 9491 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9492 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9493 | base::MessageLoop::current()->RunUntilIdle(); |
| 9494 | |
| 9495 | // Transaction is pending on request body initialization. |
| 9496 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 9497 | |
| 9498 | // Return Init()'s result after the transaction gets destroyed. |
| 9499 | trans.reset(); |
| 9500 | fake_reader->callback().Run(OK); // Should not crash. |
| 9501 | } |
| 9502 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9503 | // Tests that changes to Auth realms are treated like auth rejections. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9504 | TEST_P(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9505 | HttpRequestInfo request; |
| 9506 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9507 | request.url = GURL("http://www.example.org/"); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9508 | request.load_flags = 0; |
| 9509 | |
| 9510 | // First transaction will request a resource and receive a Basic challenge |
| 9511 | // with realm="first_realm". |
| 9512 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9513 | MockWrite( |
| 9514 | "GET / HTTP/1.1\r\n" |
| 9515 | "Host: www.example.org\r\n" |
| 9516 | "Connection: keep-alive\r\n" |
| 9517 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9518 | }; |
| 9519 | MockRead data_reads1[] = { |
| 9520 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9521 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 9522 | "\r\n"), |
| 9523 | }; |
| 9524 | |
| 9525 | // After calling trans->RestartWithAuth(), provide an Authentication header |
| 9526 | // for first_realm. The server will reject and provide a challenge with |
| 9527 | // second_realm. |
| 9528 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9529 | MockWrite( |
| 9530 | "GET / HTTP/1.1\r\n" |
| 9531 | "Host: www.example.org\r\n" |
| 9532 | "Connection: keep-alive\r\n" |
| 9533 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 9534 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9535 | }; |
| 9536 | MockRead data_reads2[] = { |
| 9537 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9538 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 9539 | "\r\n"), |
| 9540 | }; |
| 9541 | |
| 9542 | // This again fails, and goes back to first_realm. Make sure that the |
| 9543 | // entry is removed from cache. |
| 9544 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9545 | MockWrite( |
| 9546 | "GET / HTTP/1.1\r\n" |
| 9547 | "Host: www.example.org\r\n" |
| 9548 | "Connection: keep-alive\r\n" |
| 9549 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 9550 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9551 | }; |
| 9552 | MockRead data_reads3[] = { |
| 9553 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9554 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 9555 | "\r\n"), |
| 9556 | }; |
| 9557 | |
| 9558 | // Try one last time (with the correct password) and get the resource. |
| 9559 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9560 | MockWrite( |
| 9561 | "GET / HTTP/1.1\r\n" |
| 9562 | "Host: www.example.org\r\n" |
| 9563 | "Connection: keep-alive\r\n" |
| 9564 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 9565 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9566 | }; |
| 9567 | MockRead data_reads4[] = { |
| 9568 | MockRead("HTTP/1.1 200 OK\r\n" |
| 9569 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9570 | "Content-Length: 5\r\n" |
| 9571 | "\r\n" |
| 9572 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9573 | }; |
| 9574 | |
| 9575 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9576 | data_writes1, arraysize(data_writes1)); |
| 9577 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9578 | data_writes2, arraysize(data_writes2)); |
| 9579 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 9580 | data_writes3, arraysize(data_writes3)); |
| 9581 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 9582 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9583 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9584 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 9585 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 9586 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9587 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9588 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9589 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9590 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9591 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9592 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9593 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9594 | // Issue the first request with Authorize headers. There should be a |
| 9595 | // password prompt for first_realm waiting to be filled in after the |
| 9596 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9597 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9598 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9599 | rv = callback1.WaitForResult(); |
| 9600 | EXPECT_EQ(OK, rv); |
| 9601 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9602 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9603 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
| 9604 | ASSERT_FALSE(challenge == NULL); |
| 9605 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9606 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9607 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 9608 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9609 | |
| 9610 | // Issue the second request with an incorrect password. There should be a |
| 9611 | // password prompt for second_realm waiting to be filled in after the |
| 9612 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9613 | TestCompletionCallback callback2; |
| 9614 | rv = trans->RestartWithAuth( |
| 9615 | AuthCredentials(kFirst, kBaz), callback2.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9616 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9617 | rv = callback2.WaitForResult(); |
| 9618 | EXPECT_EQ(OK, rv); |
| 9619 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9620 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9621 | challenge = response->auth_challenge.get(); |
| 9622 | ASSERT_FALSE(challenge == NULL); |
| 9623 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9624 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9625 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 9626 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9627 | |
| 9628 | // Issue the third request with another incorrect password. There should be |
| 9629 | // a password prompt for first_realm waiting to be filled in. If the password |
| 9630 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 9631 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9632 | TestCompletionCallback callback3; |
| 9633 | rv = trans->RestartWithAuth( |
| 9634 | AuthCredentials(kSecond, kFou), callback3.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9635 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9636 | rv = callback3.WaitForResult(); |
| 9637 | EXPECT_EQ(OK, rv); |
| 9638 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9639 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9640 | challenge = response->auth_challenge.get(); |
| 9641 | ASSERT_FALSE(challenge == NULL); |
| 9642 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9643 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9644 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 9645 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9646 | |
| 9647 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9648 | TestCompletionCallback callback4; |
| 9649 | rv = trans->RestartWithAuth( |
| 9650 | AuthCredentials(kFirst, kBar), callback4.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9651 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9652 | rv = callback4.WaitForResult(); |
| 9653 | EXPECT_EQ(OK, rv); |
| 9654 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9655 | ASSERT_TRUE(response != NULL); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9656 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 9657 | } |
| 9658 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9659 | TEST_P(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 9660 | session_deps_.parse_alternative_services = true; |
| 9661 | session_deps_.enable_alternative_service_with_different_host = false; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9662 | |
| 9663 | std::string alternative_service_http_header = |
| 9664 | GetAlternativeServiceHttpHeader(); |
| 9665 | |
| 9666 | MockRead data_reads[] = { |
| 9667 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9668 | MockRead(alternative_service_http_header.c_str()), |
| 9669 | MockRead("\r\n"), |
| 9670 | MockRead("hello world"), |
| 9671 | MockRead(SYNCHRONOUS, OK), |
| 9672 | }; |
| 9673 | |
| 9674 | HttpRequestInfo request; |
| 9675 | request.method = "GET"; |
| 9676 | request.url = GURL("http://www.example.org/"); |
| 9677 | request.load_flags = 0; |
| 9678 | |
| 9679 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9680 | |
| 9681 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9682 | |
| 9683 | TestCompletionCallback callback; |
| 9684 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9685 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9686 | scoped_ptr<HttpTransaction> trans( |
| 9687 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9688 | |
| 9689 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9690 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9691 | |
| 9692 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9693 | HttpServerProperties& http_server_properties = |
| 9694 | *session->http_server_properties(); |
| 9695 | AlternativeServiceVector alternative_service_vector = |
| 9696 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9697 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9698 | |
| 9699 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9700 | |
| 9701 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9702 | ASSERT_TRUE(response != NULL); |
| 9703 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9704 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9705 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9706 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9707 | |
| 9708 | std::string response_data; |
| 9709 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9710 | EXPECT_EQ("hello world", response_data); |
| 9711 | |
| 9712 | alternative_service_vector = |
| 9713 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9714 | ASSERT_EQ(1u, alternative_service_vector.size()); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9715 | EXPECT_EQ(AlternateProtocolFromNextProto(GetProtocol()), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9716 | alternative_service_vector[0].protocol); |
| 9717 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 9718 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 9719 | } |
| 9720 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 9721 | TEST_P(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 9722 | session_deps_.parse_alternative_services = true; |
| 9723 | session_deps_.enable_alternative_service_with_different_host = false; |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 9724 | |
| 9725 | // Set an alternative service for origin. |
| 9726 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9727 | HttpServerProperties& http_server_properties = |
| 9728 | *session->http_server_properties(); |
| 9729 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9730 | AlternativeService alternative_service(QUIC, "", 80); |
| 9731 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 9732 | http_server_properties.SetAlternativeService(http_host_port_pair, |
| 9733 | alternative_service, expiration); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 9734 | AlternativeServiceVector alternative_service_vector = |
| 9735 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9736 | EXPECT_EQ(1u, alternative_service_vector.size()); |
| 9737 | |
| 9738 | // Send a clear header. |
| 9739 | MockRead data_reads[] = { |
| 9740 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9741 | MockRead("Alt-Svc: clear\r\n"), |
| 9742 | MockRead("\r\n"), |
| 9743 | MockRead("hello world"), |
| 9744 | MockRead(SYNCHRONOUS, OK), |
| 9745 | }; |
| 9746 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 9747 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9748 | |
| 9749 | HttpRequestInfo request; |
| 9750 | request.method = "GET"; |
| 9751 | request.url = GURL("http://www.example.org/"); |
| 9752 | request.load_flags = 0; |
| 9753 | |
| 9754 | TestCompletionCallback callback; |
| 9755 | |
| 9756 | scoped_ptr<HttpTransaction> trans( |
| 9757 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9758 | |
| 9759 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9760 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 9761 | |
| 9762 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9763 | ASSERT_TRUE(response != nullptr); |
| 9764 | ASSERT_TRUE(response->headers.get() != nullptr); |
| 9765 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9766 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9767 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9768 | |
| 9769 | std::string response_data; |
| 9770 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9771 | EXPECT_EQ("hello world", response_data); |
| 9772 | |
| 9773 | alternative_service_vector = |
| 9774 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9775 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9776 | } |
| 9777 | |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 9778 | // Alternative Service headers must be ignored when |
| 9779 | // |parse_alternative_services| is false. |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9780 | TEST_P(HttpNetworkTransactionTest, DoNotHonorAlternativeServiceHeader) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 9781 | session_deps_.parse_alternative_services = false; |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9782 | |
| 9783 | std::string alternative_service_http_header = |
| 9784 | GetAlternativeServiceHttpHeader(); |
| 9785 | |
| 9786 | MockRead data_reads[] = { |
| 9787 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9788 | MockRead(alternative_service_http_header.c_str()), |
| 9789 | MockRead("\r\n"), |
| 9790 | MockRead("hello world"), |
| 9791 | MockRead(SYNCHRONOUS, OK), |
| 9792 | }; |
| 9793 | |
| 9794 | HttpRequestInfo request; |
| 9795 | request.method = "GET"; |
| 9796 | request.url = GURL("http://www.example.org/"); |
| 9797 | request.load_flags = 0; |
| 9798 | |
| 9799 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 9800 | |
| 9801 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9802 | |
| 9803 | TestCompletionCallback callback; |
| 9804 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9805 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9806 | scoped_ptr<HttpTransaction> trans( |
| 9807 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9808 | |
| 9809 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9810 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9811 | |
| 9812 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9813 | HttpServerProperties& http_server_properties = |
| 9814 | *session->http_server_properties(); |
| 9815 | AlternativeServiceVector alternative_service_vector = |
| 9816 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9817 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9818 | |
| 9819 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9820 | |
| 9821 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9822 | ASSERT_TRUE(response != nullptr); |
| 9823 | ASSERT_TRUE(response->headers.get() != nullptr); |
| 9824 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9825 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9826 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9827 | |
| 9828 | std::string response_data; |
| 9829 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9830 | EXPECT_EQ("hello world", response_data); |
| 9831 | |
| 9832 | alternative_service_vector = |
| 9833 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9834 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9835 | } |
| 9836 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9837 | TEST_P(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeader) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 9838 | session_deps_.parse_alternative_services = true; |
| 9839 | session_deps_.enable_alternative_service_with_different_host = false; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9840 | |
| 9841 | MockRead data_reads[] = { |
| 9842 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9843 | MockRead("Alt-Svc: "), |
| 9844 | MockRead(GetAlternateProtocolFromParam()), |
bnc | 44858c8 | 2015-10-16 11:57:21 | [diff] [blame] | 9845 | MockRead("=\"www.example.com:443\";p=\"1.0\","), |
bnc | 3f0118e | 2016-02-02 15:42:22 | [diff] [blame] | 9846 | MockRead(GetAlternateProtocolFromParam()), |
| 9847 | MockRead("=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9848 | MockRead("hello world"), |
| 9849 | MockRead(SYNCHRONOUS, OK), |
| 9850 | }; |
| 9851 | |
| 9852 | HttpRequestInfo request; |
| 9853 | request.method = "GET"; |
| 9854 | request.url = GURL("http://www.example.org/"); |
| 9855 | request.load_flags = 0; |
| 9856 | |
| 9857 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9858 | |
| 9859 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9860 | |
| 9861 | TestCompletionCallback callback; |
| 9862 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9863 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9864 | scoped_ptr<HttpTransaction> trans( |
| 9865 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9866 | |
| 9867 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9868 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9869 | |
| 9870 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9871 | HttpServerProperties& http_server_properties = |
| 9872 | *session->http_server_properties(); |
| 9873 | AlternativeServiceVector alternative_service_vector = |
| 9874 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9875 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9876 | |
| 9877 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9878 | |
| 9879 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9880 | ASSERT_TRUE(response != NULL); |
| 9881 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9882 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9883 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9884 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9885 | |
| 9886 | std::string response_data; |
| 9887 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9888 | EXPECT_EQ("hello world", response_data); |
| 9889 | |
| 9890 | alternative_service_vector = |
| 9891 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9892 | ASSERT_EQ(2u, alternative_service_vector.size()); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9893 | EXPECT_EQ(AlternateProtocolFromNextProto(GetProtocol()), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9894 | alternative_service_vector[0].protocol); |
| 9895 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 9896 | EXPECT_EQ(443, alternative_service_vector[0].port); |
bnc | 3f0118e | 2016-02-02 15:42:22 | [diff] [blame] | 9897 | EXPECT_EQ(AlternateProtocolFromNextProto(GetProtocol()), |
| 9898 | alternative_service_vector[1].protocol); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9899 | EXPECT_EQ("www.example.org", alternative_service_vector[1].host); |
| 9900 | EXPECT_EQ(1234, alternative_service_vector[1].port); |
| 9901 | } |
| 9902 | |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 9903 | // Alternate Protocol headers must be honored even if |
| 9904 | // |parse_alternative_services| is false. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9905 | TEST_P(HttpNetworkTransactionTest, HonorAlternateProtocolHeader) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 9906 | session_deps_.parse_alternative_services = false; |
[email protected] | a2cb812 | 2010-03-10 17:22:42 | [diff] [blame] | 9907 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9908 | std::string alternate_protocol_http_header = |
| 9909 | GetAlternateProtocolHttpHeader(); |
| 9910 | |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9911 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9912 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9913 | MockRead(alternate_protocol_http_header.c_str()), |
| 9914 | MockRead("\r\n"), |
| 9915 | MockRead("hello world"), |
| 9916 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9917 | }; |
| 9918 | |
| 9919 | HttpRequestInfo request; |
| 9920 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9921 | request.url = GURL("http://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9922 | request.load_flags = 0; |
| 9923 | |
| 9924 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9925 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9926 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9927 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9928 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9929 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9930 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9931 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9932 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9933 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9934 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9935 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 9936 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9937 | HostPortPair http_host_port_pair("www.example.org", 80); |
[email protected] | 9801e370 | 2014-03-07 09:33:55 | [diff] [blame] | 9938 | HttpServerProperties& http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9939 | *session->http_server_properties(); |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9940 | AlternativeServiceVector alternative_service_vector = |
| 9941 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9942 | EXPECT_TRUE(alternative_service_vector.empty()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9943 | |
| 9944 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9945 | |
| 9946 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9947 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9948 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9949 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9950 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9951 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9952 | |
| 9953 | std::string response_data; |
| 9954 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9955 | EXPECT_EQ("hello world", response_data); |
| 9956 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9957 | alternative_service_vector = |
| 9958 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9959 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9960 | EXPECT_EQ(443, alternative_service_vector[0].port); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9961 | EXPECT_EQ(AlternateProtocolFromNextProto(GetProtocol()), |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9962 | alternative_service_vector[0].protocol); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9963 | } |
| 9964 | |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9965 | TEST_P(HttpNetworkTransactionTest, EmptyAlternateProtocolHeader) { |
rch | 3f4b845 | 2016-02-23 16:59:32 | [diff] [blame] | 9966 | session_deps_.parse_alternative_services = false; |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 9967 | session_deps_.enable_alternative_service_with_different_host = false; |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9968 | |
| 9969 | MockRead data_reads[] = { |
| 9970 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9971 | MockRead("Alternate-Protocol: \r\n\r\n"), |
| 9972 | MockRead("hello world"), |
| 9973 | MockRead(SYNCHRONOUS, OK), |
| 9974 | }; |
| 9975 | |
| 9976 | HttpRequestInfo request; |
| 9977 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9978 | request.url = GURL("http://www.example.org/"); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9979 | request.load_flags = 0; |
| 9980 | |
| 9981 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9982 | |
| 9983 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9984 | |
| 9985 | TestCompletionCallback callback; |
| 9986 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9987 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9988 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9989 | HostPortPair http_host_port_pair("www.example.org", 80); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9990 | HttpServerProperties& http_server_properties = |
| 9991 | *session->http_server_properties(); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9992 | AlternativeService alternative_service(QUIC, "", 80); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9993 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 9994 | http_server_properties.SetAlternativeService(http_host_port_pair, |
| 9995 | alternative_service, expiration); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9996 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9997 | AlternativeServiceVector alternative_service_vector = |
| 9998 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9999 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 10000 | EXPECT_EQ(QUIC, alternative_service_vector[0].protocol); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 10001 | |
| 10002 | scoped_ptr<HttpTransaction> trans( |
| 10003 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 10004 | |
| 10005 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10006 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10007 | |
| 10008 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10009 | |
| 10010 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10011 | ASSERT_TRUE(response != NULL); |
| 10012 | ASSERT_TRUE(response->headers.get() != NULL); |
| 10013 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10014 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10015 | EXPECT_FALSE(response->was_npn_negotiated); |
| 10016 | |
| 10017 | std::string response_data; |
| 10018 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10019 | EXPECT_EQ("hello world", response_data); |
| 10020 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10021 | alternative_service_vector = |
| 10022 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 10023 | EXPECT_TRUE(alternative_service_vector.empty()); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 10024 | } |
| 10025 | |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10026 | // When |session_deps_.parse_alternative_services = true| and the response has |
| 10027 | // an Alt-Svc header, then the Alternate-Protocol header is not parsed. |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10028 | TEST_P(HttpNetworkTransactionTest, AltSvcOverwritesAlternateProtocol) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10029 | session_deps_.parse_alternative_services = true; |
| 10030 | session_deps_.enable_alternative_service_with_different_host = false; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10031 | |
| 10032 | std::string alternative_service_http_header = |
| 10033 | GetAlternativeServiceHttpHeader(); |
| 10034 | std::string alternate_protocol_http_header = GetAlternateProtocolHttpHeader(); |
| 10035 | |
| 10036 | MockRead data_reads[] = { |
| 10037 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10038 | MockRead(alternative_service_http_header.c_str()), |
| 10039 | MockRead(alternate_protocol_http_header.c_str()), |
| 10040 | MockRead("\r\n"), |
| 10041 | MockRead("hello world"), |
| 10042 | MockRead(SYNCHRONOUS, OK), |
| 10043 | }; |
| 10044 | |
| 10045 | HttpRequestInfo request; |
| 10046 | request.method = "GET"; |
| 10047 | request.url = GURL("http://www.example.org/"); |
| 10048 | request.load_flags = 0; |
| 10049 | |
| 10050 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10051 | |
| 10052 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10053 | |
| 10054 | TestCompletionCallback callback; |
| 10055 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10056 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10057 | scoped_ptr<HttpTransaction> trans( |
| 10058 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 10059 | |
| 10060 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10061 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10062 | |
| 10063 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 10064 | HttpServerProperties& http_server_properties = |
| 10065 | *session->http_server_properties(); |
| 10066 | AlternativeServiceVector alternative_service_vector = |
| 10067 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 10068 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 10069 | |
| 10070 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10071 | |
| 10072 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10073 | ASSERT_TRUE(response != NULL); |
| 10074 | ASSERT_TRUE(response->headers.get() != NULL); |
| 10075 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10076 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10077 | EXPECT_FALSE(response->was_npn_negotiated); |
| 10078 | |
| 10079 | std::string response_data; |
| 10080 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10081 | EXPECT_EQ("hello world", response_data); |
| 10082 | |
| 10083 | alternative_service_vector = |
| 10084 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 10085 | ASSERT_EQ(1u, alternative_service_vector.size()); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10086 | EXPECT_EQ(AlternateProtocolFromNextProto(GetProtocol()), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10087 | alternative_service_vector[0].protocol); |
| 10088 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 10089 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 10090 | } |
| 10091 | |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10092 | // When |enable_alternative_service_with_different_host| is false, do not |
| 10093 | // observe alternative service entries that point to a different host. |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 10094 | TEST_P(HttpNetworkTransactionTest, DisableAlternativeServiceToDifferentHost) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10095 | session_deps_.parse_alternative_services = true; |
| 10096 | session_deps_.enable_alternative_service_with_different_host = false; |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 10097 | |
| 10098 | HttpRequestInfo request; |
| 10099 | request.method = "GET"; |
| 10100 | request.url = GURL("http://www.example.org/"); |
| 10101 | request.load_flags = 0; |
| 10102 | |
| 10103 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10104 | StaticSocketDataProvider first_data; |
| 10105 | first_data.set_connect_data(mock_connect); |
| 10106 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 10107 | |
| 10108 | MockRead data_reads[] = { |
| 10109 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10110 | MockRead(ASYNC, OK), |
| 10111 | }; |
| 10112 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), |
| 10113 | nullptr, 0); |
| 10114 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10115 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10116 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 10117 | |
| 10118 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 10119 | session->http_server_properties(); |
| 10120 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10121 | AlternateProtocolFromNextProto(GetProtocol()), "different.example.org", |
| 10122 | 80); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 10123 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10124 | http_server_properties->SetAlternativeService( |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10125 | HostPortPair::FromURL(request.url), alternative_service, expiration); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 10126 | |
| 10127 | scoped_ptr<HttpTransaction> trans( |
| 10128 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 10129 | TestCompletionCallback callback; |
| 10130 | |
| 10131 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10132 | // The connetion to origin was refused, and the alternative service should not |
| 10133 | // be used (even though mock data are there), therefore the request should |
| 10134 | // fail. |
| 10135 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.GetResult(rv)); |
| 10136 | } |
| 10137 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10138 | TEST_P(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
| 10139 | HostPortPair origin("origin.example.org", 443); |
| 10140 | HostPortPair alternative("alternative.example.org", 443); |
| 10141 | std::string origin_url = "https://origin.example.org:443"; |
| 10142 | std::string alternative_url = "https://alternative.example.org:443"; |
| 10143 | |
| 10144 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 10145 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10146 | ssl.SetNextProto(kProtoHTTP11); |
| 10147 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10148 | |
| 10149 | // HTTP/1.1 data for request. |
| 10150 | MockWrite http_writes[] = { |
| 10151 | MockWrite("GET / HTTP/1.1\r\n" |
| 10152 | "Host: alternative.example.org\r\n" |
| 10153 | "Connection: keep-alive\r\n\r\n"), |
| 10154 | }; |
| 10155 | |
| 10156 | MockRead http_reads[] = { |
| 10157 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10158 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10159 | "Content-Length: 40\r\n\r\n" |
| 10160 | "first HTTP/1.1 response from alternative"), |
| 10161 | }; |
| 10162 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10163 | http_writes, arraysize(http_writes)); |
| 10164 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10165 | |
| 10166 | StaticSocketDataProvider data_refused; |
| 10167 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10168 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10169 | |
| 10170 | // Set up a QUIC alternative service for origin. |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10171 | session_deps_.parse_alternative_services = true; |
| 10172 | session_deps_.enable_alternative_service_with_different_host = false; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10173 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10174 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 10175 | session->http_server_properties(); |
| 10176 | AlternativeService alternative_service(QUIC, alternative); |
| 10177 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10178 | http_server_properties->SetAlternativeService(origin, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10179 | expiration); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10180 | // Mark the QUIC alternative service as broken. |
| 10181 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 10182 | |
| 10183 | scoped_ptr<HttpTransaction> trans( |
| 10184 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 10185 | HttpRequestInfo request; |
| 10186 | request.method = "GET"; |
| 10187 | request.url = GURL(origin_url); |
| 10188 | request.load_flags = 0; |
| 10189 | TestCompletionCallback callback; |
| 10190 | NetErrorDetails details; |
| 10191 | EXPECT_FALSE(details.quic_broken); |
| 10192 | |
| 10193 | trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10194 | trans->PopulateNetErrorDetails(&details); |
| 10195 | EXPECT_TRUE(details.quic_broken); |
| 10196 | } |
| 10197 | |
| 10198 | TEST_P(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
| 10199 | HostPortPair origin("origin.example.org", 443); |
| 10200 | HostPortPair alternative1("alternative1.example.org", 443); |
| 10201 | HostPortPair alternative2("alternative2.example.org", 443); |
| 10202 | std::string origin_url = "https://origin.example.org:443"; |
| 10203 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 10204 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 10205 | |
| 10206 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 10207 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10208 | ssl.SetNextProto(kProtoHTTP11); |
| 10209 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10210 | |
| 10211 | // HTTP/1.1 data for request. |
| 10212 | MockWrite http_writes[] = { |
| 10213 | MockWrite("GET / HTTP/1.1\r\n" |
| 10214 | "Host: alternative1.example.org\r\n" |
| 10215 | "Connection: keep-alive\r\n\r\n"), |
| 10216 | }; |
| 10217 | |
| 10218 | MockRead http_reads[] = { |
| 10219 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10220 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10221 | "Content-Length: 40\r\n\r\n" |
| 10222 | "first HTTP/1.1 response from alternative1"), |
| 10223 | }; |
| 10224 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10225 | http_writes, arraysize(http_writes)); |
| 10226 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10227 | |
| 10228 | StaticSocketDataProvider data_refused; |
| 10229 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10230 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10231 | |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10232 | session_deps_.parse_alternative_services = true; |
| 10233 | session_deps_.enable_alternative_service_with_different_host = true; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10234 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10235 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 10236 | session->http_server_properties(); |
| 10237 | |
| 10238 | // Set up two QUIC alternative services for origin. |
| 10239 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 10240 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10241 | |
| 10242 | AlternativeService alternative_service1(QUIC, alternative1); |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10243 | AlternativeServiceInfo alternative_service_info1(alternative_service1, |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10244 | expiration); |
| 10245 | alternative_service_info_vector.push_back(alternative_service_info1); |
| 10246 | AlternativeService alternative_service2(QUIC, alternative2); |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10247 | AlternativeServiceInfo alternative_service_info2(alternative_service2, |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10248 | expiration); |
| 10249 | alternative_service_info_vector.push_back(alternative_service_info2); |
| 10250 | |
| 10251 | http_server_properties->SetAlternativeServices( |
| 10252 | origin, alternative_service_info_vector); |
| 10253 | |
| 10254 | // Mark one of the QUIC alternative service as broken. |
| 10255 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
| 10256 | |
| 10257 | const AlternativeServiceVector alternative_service_vector = |
| 10258 | http_server_properties->GetAlternativeServices(origin); |
| 10259 | |
| 10260 | scoped_ptr<HttpTransaction> trans( |
| 10261 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 10262 | HttpRequestInfo request; |
| 10263 | request.method = "GET"; |
| 10264 | request.url = GURL(origin_url); |
| 10265 | request.load_flags = 0; |
| 10266 | TestCompletionCallback callback; |
| 10267 | NetErrorDetails details; |
| 10268 | EXPECT_FALSE(details.quic_broken); |
| 10269 | |
| 10270 | trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10271 | trans->PopulateNetErrorDetails(&details); |
| 10272 | EXPECT_FALSE(details.quic_broken); |
| 10273 | } |
| 10274 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10275 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10276 | MarkBrokenAlternateProtocolAndFallback) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10277 | session_deps_.parse_alternative_services = true; |
| 10278 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10279 | |
| 10280 | HttpRequestInfo request; |
| 10281 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10282 | request.url = GURL("http://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10283 | request.load_flags = 0; |
| 10284 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10285 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10286 | StaticSocketDataProvider first_data; |
| 10287 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10288 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10289 | |
| 10290 | MockRead data_reads[] = { |
| 10291 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10292 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10293 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10294 | }; |
| 10295 | StaticSocketDataProvider second_data( |
| 10296 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10297 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10298 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10299 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10300 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10301 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10302 | session->http_server_properties(); |
bnc | 8445b300 | 2015-03-13 01:57:09 | [diff] [blame] | 10303 | const HostPortPair host_port_pair = HostPortPair::FromURL(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10304 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 10305 | // port 80 (another restricted port). |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10306 | const AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10307 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10308 | 666); // Port is ignored by MockConnect anyway. |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10309 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10310 | http_server_properties->SetAlternativeService( |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10311 | host_port_pair, alternative_service, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10312 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10313 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10314 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10315 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10316 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10317 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10318 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10319 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10320 | |
| 10321 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10322 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10323 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10324 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10325 | |
| 10326 | std::string response_data; |
| 10327 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10328 | EXPECT_EQ("hello world", response_data); |
| 10329 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10330 | const AlternativeServiceVector alternative_service_vector = |
| 10331 | http_server_properties->GetAlternativeServices(host_port_pair); |
| 10332 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 10333 | EXPECT_EQ(alternative_service, alternative_service_vector[0]); |
| 10334 | EXPECT_TRUE(http_server_properties->IsAlternativeServiceBroken( |
| 10335 | alternative_service_vector[0])); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10336 | } |
| 10337 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10338 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10339 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10340 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10341 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10342 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10343 | AlternateProtocolPortRestrictedBlocked) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10344 | session_deps_.parse_alternative_services = true; |
| 10345 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10346 | |
| 10347 | HttpRequestInfo restricted_port_request; |
| 10348 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10349 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10350 | restricted_port_request.load_flags = 0; |
| 10351 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10352 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10353 | StaticSocketDataProvider first_data; |
| 10354 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10355 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10356 | |
| 10357 | MockRead data_reads[] = { |
| 10358 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10359 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10360 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10361 | }; |
| 10362 | StaticSocketDataProvider second_data( |
| 10363 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10364 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10365 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10366 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10367 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10368 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10369 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10370 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10371 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10372 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10373 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10374 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10375 | http_server_properties->SetAlternativeService( |
| 10376 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10377 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10378 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10379 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10380 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10381 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10382 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10383 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10384 | &restricted_port_request, |
| 10385 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10386 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10387 | // Invalid change to unrestricted port should fail. |
| 10388 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10389 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10390 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10391 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 10392 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 10393 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10394 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10395 | AlternateProtocolPortRestrictedPermitted) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10396 | session_deps_.parse_alternative_services = true; |
| 10397 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10398 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10399 | |
| 10400 | HttpRequestInfo restricted_port_request; |
| 10401 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10402 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10403 | restricted_port_request.load_flags = 0; |
| 10404 | |
| 10405 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10406 | StaticSocketDataProvider first_data; |
| 10407 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10408 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10409 | |
| 10410 | MockRead data_reads[] = { |
| 10411 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10412 | MockRead("hello world"), |
| 10413 | MockRead(ASYNC, OK), |
| 10414 | }; |
| 10415 | StaticSocketDataProvider second_data( |
| 10416 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10417 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10418 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10419 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10420 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10421 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10422 | session->http_server_properties(); |
| 10423 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10424 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10425 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10426 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10427 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10428 | http_server_properties->SetAlternativeService( |
| 10429 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10430 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10431 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10432 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10433 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10434 | TestCompletionCallback callback; |
| 10435 | |
| 10436 | EXPECT_EQ(ERR_IO_PENDING, trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10437 | &restricted_port_request, |
| 10438 | callback.callback(), BoundNetLog())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10439 | // Change to unrestricted port should succeed. |
| 10440 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10441 | } |
| 10442 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10443 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10444 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10445 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10446 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10447 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10448 | AlternateProtocolPortRestrictedAllowed) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10449 | session_deps_.parse_alternative_services = true; |
| 10450 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10451 | |
| 10452 | HttpRequestInfo restricted_port_request; |
| 10453 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10454 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10455 | restricted_port_request.load_flags = 0; |
| 10456 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10457 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10458 | StaticSocketDataProvider first_data; |
| 10459 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10460 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10461 | |
| 10462 | MockRead data_reads[] = { |
| 10463 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10464 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10465 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10466 | }; |
| 10467 | StaticSocketDataProvider second_data( |
| 10468 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10469 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10470 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10471 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10472 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10473 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10474 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10475 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10476 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10477 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10478 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10479 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10480 | http_server_properties->SetAlternativeService( |
| 10481 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10482 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10483 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10484 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10485 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10486 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10487 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10488 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10489 | &restricted_port_request, |
| 10490 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10491 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10492 | // Valid change to restricted port should pass. |
| 10493 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10494 | } |
| 10495 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10496 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10497 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10498 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10499 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10500 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10501 | AlternateProtocolPortUnrestrictedAllowed1) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10502 | session_deps_.parse_alternative_services = true; |
| 10503 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10504 | |
| 10505 | HttpRequestInfo unrestricted_port_request; |
| 10506 | unrestricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10507 | unrestricted_port_request.url = GURL("http://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10508 | unrestricted_port_request.load_flags = 0; |
| 10509 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10510 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10511 | StaticSocketDataProvider first_data; |
| 10512 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10513 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10514 | |
| 10515 | MockRead data_reads[] = { |
| 10516 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10517 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10518 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10519 | }; |
| 10520 | StaticSocketDataProvider second_data( |
| 10521 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10522 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10523 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10524 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10525 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10526 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10527 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10528 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10529 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10530 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10531 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10532 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10533 | http_server_properties->SetAlternativeService( |
| 10534 | HostPortPair::FromURL(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10535 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10536 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10537 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10538 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10539 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10540 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10541 | int rv = trans->Start( |
| 10542 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10543 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10544 | // Valid change to restricted port should pass. |
| 10545 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10546 | } |
| 10547 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10548 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10549 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10550 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10551 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10552 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10553 | AlternateProtocolPortUnrestrictedAllowed2) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10554 | session_deps_.parse_alternative_services = true; |
| 10555 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10556 | |
| 10557 | HttpRequestInfo unrestricted_port_request; |
| 10558 | unrestricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10559 | unrestricted_port_request.url = GURL("http://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10560 | unrestricted_port_request.load_flags = 0; |
| 10561 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10562 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10563 | StaticSocketDataProvider first_data; |
| 10564 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10565 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10566 | |
| 10567 | MockRead data_reads[] = { |
| 10568 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10569 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10570 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10571 | }; |
| 10572 | StaticSocketDataProvider second_data( |
| 10573 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10574 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10575 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10576 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10577 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10578 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10579 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 10580 | const int kUnrestrictedAlternatePort = 1025; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10581 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10582 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10583 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10584 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10585 | http_server_properties->SetAlternativeService( |
| 10586 | HostPortPair::FromURL(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10587 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10588 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10589 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10590 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10591 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10592 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10593 | int rv = trans->Start( |
| 10594 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10595 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10596 | // Valid change to an unrestricted port should pass. |
| 10597 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10598 | } |
| 10599 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10600 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10601 | // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job |
| 10602 | // once the alternate protocol request fails. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10603 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10604 | session_deps_.parse_alternative_services = true; |
| 10605 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10606 | |
| 10607 | HttpRequestInfo request; |
| 10608 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10609 | request.url = GURL("http://www.example.org/"); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10610 | request.load_flags = 0; |
| 10611 | |
| 10612 | // The alternate protocol request will error out before we attempt to connect, |
| 10613 | // so only the standard HTTP request will try to connect. |
| 10614 | MockRead data_reads[] = { |
| 10615 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10616 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10617 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10618 | }; |
| 10619 | StaticSocketDataProvider data( |
| 10620 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10621 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10622 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10623 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10624 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10625 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10626 | session->http_server_properties(); |
| 10627 | const int kUnsafePort = 7; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10628 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10629 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10630 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10631 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10632 | http_server_properties->SetAlternativeService( |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10633 | HostPortPair::FromURL(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10634 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10635 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10636 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10637 | TestCompletionCallback callback; |
| 10638 | |
| 10639 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10640 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10641 | // The HTTP request should succeed. |
| 10642 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10643 | |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10644 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10645 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10646 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10647 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10648 | |
| 10649 | std::string response_data; |
| 10650 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10651 | EXPECT_EQ("hello world", response_data); |
| 10652 | } |
| 10653 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10654 | TEST_P(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
rch | 3f4b845 | 2016-02-23 16:59:32 | [diff] [blame] | 10655 | session_deps_.parse_alternative_services = false; |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10656 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10657 | |
| 10658 | HttpRequestInfo request; |
| 10659 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10660 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10661 | request.load_flags = 0; |
| 10662 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10663 | std::string alternate_protocol_http_header = |
| 10664 | GetAlternateProtocolHttpHeader(); |
| 10665 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10666 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10667 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10668 | MockRead(alternate_protocol_http_header.c_str()), |
| 10669 | MockRead("\r\n"), |
| 10670 | MockRead("hello world"), |
| 10671 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10672 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10673 | |
| 10674 | StaticSocketDataProvider first_transaction( |
| 10675 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10676 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10677 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10678 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10679 | ssl.SetNextProto(GetProtocol()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10680 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10681 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10682 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10683 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 10684 | scoped_ptr<SpdySerializedFrame> req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 10685 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10686 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10687 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 10688 | scoped_ptr<SpdySerializedFrame> resp( |
| 10689 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10690 | scoped_ptr<SpdySerializedFrame> data( |
| 10691 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10692 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10693 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10694 | }; |
| 10695 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10696 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10697 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10698 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10699 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10700 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10701 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10702 | NULL, 0, NULL, 0); |
| 10703 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10704 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10705 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10706 | &hanging_non_alternate_protocol_socket); |
| 10707 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10708 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10709 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10710 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10711 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10712 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10713 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10714 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10715 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10716 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10717 | |
| 10718 | const HttpResponseInfo* response = trans->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] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10721 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10722 | |
| 10723 | std::string response_data; |
| 10724 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10725 | EXPECT_EQ("hello world", response_data); |
| 10726 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10727 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10728 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10729 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10730 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10731 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10732 | |
| 10733 | response = trans->GetResponseInfo(); |
| 10734 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10735 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 10736 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10737 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10738 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10739 | |
| 10740 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10741 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10742 | } |
| 10743 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10744 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
rch | 3f4b845 | 2016-02-23 16:59:32 | [diff] [blame] | 10745 | session_deps_.parse_alternative_services = false; |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10746 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10747 | |
| 10748 | HttpRequestInfo request; |
| 10749 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10750 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10751 | request.load_flags = 0; |
| 10752 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10753 | std::string alternate_protocol_http_header = |
| 10754 | GetAlternateProtocolHttpHeader(); |
| 10755 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10756 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10757 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10758 | MockRead(alternate_protocol_http_header.c_str()), |
| 10759 | MockRead("\r\n"), |
| 10760 | MockRead("hello world"), |
| 10761 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10762 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10763 | }; |
| 10764 | |
| 10765 | StaticSocketDataProvider first_transaction( |
| 10766 | data_reads, arraysize(data_reads), NULL, 0); |
| 10767 | // Socket 1 is the HTTP transaction with the Alternate-Protocol header. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10768 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10769 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10770 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10771 | StaticSocketDataProvider hanging_socket1(NULL, 0, NULL, 0); |
| 10772 | hanging_socket1.set_connect_data(never_finishing_connect); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10773 | // Socket 2 and 3 are the hanging Alternate-Protocol and |
| 10774 | // non-Alternate-Protocol jobs from the 2nd transaction. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10775 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 10776 | |
| 10777 | StaticSocketDataProvider hanging_socket2(NULL, 0, NULL, 0); |
| 10778 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 10779 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10780 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10781 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10782 | ssl.SetNextProto(GetProtocol()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10783 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10784 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10785 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10786 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 10787 | scoped_ptr<SpdySerializedFrame> req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 10788 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 10789 | scoped_ptr<SpdySerializedFrame> req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 10790 | spdy_util_.ConstructSpdyGet(nullptr, 0, 3, LOWEST, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10791 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10792 | CreateMockWrite(*req1, 0), CreateMockWrite(*req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10793 | }; |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 10794 | scoped_ptr<SpdySerializedFrame> resp1( |
| 10795 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10796 | scoped_ptr<SpdySerializedFrame> data1( |
| 10797 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 10798 | scoped_ptr<SpdySerializedFrame> resp2( |
| 10799 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 10800 | scoped_ptr<SpdySerializedFrame> data2( |
| 10801 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10802 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10803 | CreateMockRead(*resp1, 2), |
| 10804 | CreateMockRead(*data1, 3), |
| 10805 | CreateMockRead(*resp2, 4), |
| 10806 | CreateMockRead(*data2, 5), |
| 10807 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10808 | }; |
| 10809 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10810 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10811 | arraysize(spdy_writes)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10812 | // Socket 4 is the successful Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10813 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10814 | |
| 10815 | // Socket 5 is the unsuccessful non-Alternate-Protocol for transaction 3. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10816 | StaticSocketDataProvider hanging_socket3(NULL, 0, NULL, 0); |
| 10817 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 10818 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10819 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10820 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10821 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10822 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10823 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10824 | int rv = trans1.Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10825 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10826 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 10827 | |
| 10828 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 10829 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10830 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10831 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10832 | |
| 10833 | std::string response_data; |
| 10834 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 10835 | EXPECT_EQ("hello world", response_data); |
| 10836 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10837 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10838 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10839 | rv = trans2.Start(&request, callback2.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10840 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10841 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10842 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10843 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10844 | rv = trans3.Start(&request, callback3.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10845 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10846 | |
| 10847 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 10848 | EXPECT_EQ(OK, callback3.WaitForResult()); |
| 10849 | |
| 10850 | response = trans2.GetResponseInfo(); |
| 10851 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10852 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 10853 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10854 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10855 | EXPECT_TRUE(response->was_npn_negotiated); |
| 10856 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 10857 | EXPECT_EQ("hello!", response_data); |
| 10858 | |
| 10859 | response = trans3.GetResponseInfo(); |
| 10860 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10861 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 10862 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10863 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10864 | EXPECT_TRUE(response->was_npn_negotiated); |
| 10865 | ASSERT_EQ(OK, ReadTransaction(&trans3, &response_data)); |
| 10866 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10867 | } |
| 10868 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10869 | TEST_P(HttpNetworkTransactionTest, StallAlternateProtocolForNpnSpdy) { |
rch | 3f4b845 | 2016-02-23 16:59:32 | [diff] [blame] | 10870 | session_deps_.parse_alternative_services = false; |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10871 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10872 | |
| 10873 | HttpRequestInfo request; |
| 10874 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10875 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10876 | request.load_flags = 0; |
| 10877 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10878 | std::string alternate_protocol_http_header = |
| 10879 | GetAlternateProtocolHttpHeader(); |
| 10880 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10881 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10882 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10883 | MockRead(alternate_protocol_http_header.c_str()), |
| 10884 | MockRead("\r\n"), |
| 10885 | MockRead("hello world"), |
| 10886 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10887 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10888 | }; |
| 10889 | |
| 10890 | StaticSocketDataProvider first_transaction( |
| 10891 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10892 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10893 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10894 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10895 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10896 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10897 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10898 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10899 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 10900 | NULL, 0, NULL, 0); |
| 10901 | hanging_alternate_protocol_socket.set_connect_data( |
| 10902 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10903 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10904 | &hanging_alternate_protocol_socket); |
| 10905 | |
| 10906 | // 2nd request is just a copy of the first one, over HTTP again. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10907 | StaticSocketDataProvider second_transaction(data_reads, arraysize(data_reads), |
| 10908 | NULL, 0); |
| 10909 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10910 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10911 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10912 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10913 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10914 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10915 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10916 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10917 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10918 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10919 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10920 | |
| 10921 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10922 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10923 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10924 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10925 | |
| 10926 | std::string response_data; |
| 10927 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10928 | EXPECT_EQ("hello world", response_data); |
| 10929 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10930 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10931 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10932 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10933 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10934 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10935 | |
| 10936 | response = trans->GetResponseInfo(); |
| 10937 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10938 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10939 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10940 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10941 | EXPECT_FALSE(response->was_npn_negotiated); |
| 10942 | |
| 10943 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10944 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10945 | } |
| 10946 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10947 | class CapturingProxyResolver : public ProxyResolver { |
| 10948 | public: |
sammc | e90c921 | 2015-05-27 23:43:35 | [diff] [blame] | 10949 | CapturingProxyResolver() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10950 | ~CapturingProxyResolver() override {} |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10951 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10952 | int GetProxyForURL(const GURL& url, |
| 10953 | ProxyInfo* results, |
| 10954 | const CompletionCallback& callback, |
eroman | 9c8f424 | 2016-02-29 21:16:54 | [diff] [blame] | 10955 | RequestHandle* request, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10956 | const BoundNetLog& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 10957 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 10958 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 10959 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10960 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 10961 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10962 | } |
| 10963 | |
eroman | 9c8f424 | 2016-02-29 21:16:54 | [diff] [blame] | 10964 | void CancelRequest(RequestHandle request) override { NOTREACHED(); } |
| 10965 | |
| 10966 | LoadState GetLoadState(RequestHandle request) const override { |
| 10967 | NOTREACHED(); |
| 10968 | return LOAD_STATE_IDLE; |
| 10969 | } |
| 10970 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 10971 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 10972 | |
| 10973 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10974 | std::vector<GURL> resolved_; |
| 10975 | |
| 10976 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 10977 | }; |
| 10978 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 10979 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 10980 | public: |
| 10981 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 10982 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 10983 | |
| 10984 | int CreateProxyResolver( |
| 10985 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
| 10986 | scoped_ptr<ProxyResolver>* resolver, |
| 10987 | const net::CompletionCallback& callback, |
| 10988 | scoped_ptr<Request>* request) override { |
| 10989 | resolver->reset(new ForwardingProxyResolver(resolver_)); |
| 10990 | return OK; |
| 10991 | } |
| 10992 | |
| 10993 | private: |
| 10994 | ProxyResolver* resolver_; |
| 10995 | }; |
| 10996 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10997 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10998 | UseAlternateProtocolForTunneledNpnSpdy) { |
rch | 3f4b845 | 2016-02-23 16:59:32 | [diff] [blame] | 10999 | session_deps_.parse_alternative_services = false; |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 11000 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11001 | |
| 11002 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11003 | proxy_config.set_auto_detect(true); |
| 11004 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 11005 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11006 | CapturingProxyResolver capturing_proxy_resolver; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11007 | session_deps_.proxy_service.reset(new ProxyService( |
csharrison | b7e3a08 | 2015-09-22 19:13:04 | [diff] [blame] | 11008 | make_scoped_ptr(new ProxyConfigServiceFixed(proxy_config)), |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11009 | make_scoped_ptr( |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11010 | new CapturingProxyResolverFactory(&capturing_proxy_resolver)), |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 11011 | NULL)); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11012 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11013 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11014 | |
| 11015 | HttpRequestInfo request; |
| 11016 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11017 | request.url = GURL("http://www.example.org/"); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11018 | request.load_flags = 0; |
| 11019 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 11020 | std::string alternate_protocol_http_header = |
| 11021 | GetAlternateProtocolHttpHeader(); |
| 11022 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11023 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11024 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11025 | MockRead(alternate_protocol_http_header.c_str()), |
| 11026 | MockRead("\r\n"), |
| 11027 | MockRead("hello world"), |
| 11028 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11029 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11030 | }; |
| 11031 | |
| 11032 | StaticSocketDataProvider first_transaction( |
| 11033 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11034 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11035 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11036 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 11037 | ssl.SetNextProto(GetProtocol()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11038 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 11039 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11040 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11041 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 11042 | scoped_ptr<SpdySerializedFrame> req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 11043 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11044 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11045 | MockWrite(ASYNC, 0, |
| 11046 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11047 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11048 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 11049 | CreateMockWrite(*req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11050 | }; |
| 11051 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11052 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 11053 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 11054 | scoped_ptr<SpdySerializedFrame> resp( |
| 11055 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11056 | scoped_ptr<SpdySerializedFrame> data( |
| 11057 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11058 | MockRead spdy_reads[] = { |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 11059 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(*resp.get(), 3), |
| 11060 | CreateMockRead(*data.get(), 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11061 | }; |
| 11062 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11063 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11064 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11065 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11066 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11067 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11068 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11069 | NULL, 0, NULL, 0); |
| 11070 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11071 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11072 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11073 | &hanging_non_alternate_protocol_socket); |
| 11074 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11075 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11076 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11077 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11078 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11079 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11080 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11081 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11082 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11083 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11084 | |
| 11085 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11086 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11087 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11088 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11089 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 11090 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11091 | |
| 11092 | std::string response_data; |
| 11093 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11094 | EXPECT_EQ("hello world", response_data); |
| 11095 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11096 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11097 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11098 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11099 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11100 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11101 | |
| 11102 | response = trans->GetResponseInfo(); |
| 11103 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11104 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11105 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11106 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11107 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11108 | |
| 11109 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11110 | EXPECT_EQ("hello!", response_data); |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11111 | ASSERT_EQ(3u, capturing_proxy_resolver.resolved().size()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11112 | EXPECT_EQ("http://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11113 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11114 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11115 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11116 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11117 | LoadTimingInfo load_timing_info; |
| 11118 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11119 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11120 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11121 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11122 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11123 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11124 | UseAlternateProtocolForNpnSpdyWithExistingSpdySession) { |
rch | 3f4b845 | 2016-02-23 16:59:32 | [diff] [blame] | 11125 | session_deps_.parse_alternative_services = false; |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 11126 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11127 | |
| 11128 | HttpRequestInfo request; |
| 11129 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11130 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11131 | request.load_flags = 0; |
| 11132 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 11133 | std::string alternate_protocol_http_header = |
| 11134 | GetAlternateProtocolHttpHeader(); |
| 11135 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11136 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11137 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11138 | MockRead(alternate_protocol_http_header.c_str()), |
| 11139 | MockRead("\r\n"), |
| 11140 | MockRead("hello world"), |
| 11141 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11142 | }; |
| 11143 | |
| 11144 | StaticSocketDataProvider first_transaction( |
| 11145 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11146 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11147 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11148 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 11149 | ssl.SetNextProto(GetProtocol()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11150 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 11151 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11152 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11153 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 11154 | scoped_ptr<SpdySerializedFrame> req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 11155 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11156 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11157 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 11158 | scoped_ptr<SpdySerializedFrame> resp( |
| 11159 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11160 | scoped_ptr<SpdySerializedFrame> data( |
| 11161 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11162 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11163 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11164 | }; |
| 11165 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11166 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11167 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11168 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11169 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 11170 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11171 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11172 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11173 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11174 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11175 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11176 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11177 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11178 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11179 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11180 | |
| 11181 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11182 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11183 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11184 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11185 | |
| 11186 | std::string response_data; |
| 11187 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11188 | EXPECT_EQ("hello world", response_data); |
| 11189 | |
| 11190 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11191 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11192 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 11193 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11194 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11195 | CreateSecureSpdySession(session.get(), key, BoundNetLog()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 11196 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11197 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11198 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11199 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11200 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11201 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11202 | |
| 11203 | response = trans->GetResponseInfo(); |
| 11204 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11205 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11206 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11207 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11208 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11209 | |
| 11210 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11211 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11212 | } |
| 11213 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11214 | // GenerateAuthToken is a mighty big test. |
| 11215 | // It tests all permutation of GenerateAuthToken behavior: |
| 11216 | // - Synchronous and Asynchronous completion. |
| 11217 | // - OK or error on completion. |
| 11218 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 11219 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 11220 | // - Non-authenticating and authenticating backend. |
| 11221 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 11222 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11223 | // problems generating an auth token for an authenticating proxy, we don't |
| 11224 | // need to test all permutations of the backend server). |
| 11225 | // |
| 11226 | // The test proceeds by going over each of the configuration cases, and |
| 11227 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 11228 | // specifies both the configuration for the test as well as the expectations |
| 11229 | // for the results. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11230 | TEST_P(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11231 | static const char kServer[] = "http://www.example.com"; |
| 11232 | static const char kSecureServer[] = "https://www.example.com"; |
| 11233 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11234 | const int kAuthErr = ERR_INVALID_AUTH_CREDENTIALS; |
| 11235 | |
| 11236 | enum AuthTiming { |
| 11237 | AUTH_NONE, |
| 11238 | AUTH_SYNC, |
| 11239 | AUTH_ASYNC, |
| 11240 | }; |
| 11241 | |
| 11242 | const MockWrite kGet( |
| 11243 | "GET / HTTP/1.1\r\n" |
| 11244 | "Host: www.example.com\r\n" |
| 11245 | "Connection: keep-alive\r\n\r\n"); |
| 11246 | const MockWrite kGetProxy( |
| 11247 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11248 | "Host: www.example.com\r\n" |
| 11249 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11250 | const MockWrite kGetAuth( |
| 11251 | "GET / HTTP/1.1\r\n" |
| 11252 | "Host: www.example.com\r\n" |
| 11253 | "Connection: keep-alive\r\n" |
| 11254 | "Authorization: auth_token\r\n\r\n"); |
| 11255 | const MockWrite kGetProxyAuth( |
| 11256 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11257 | "Host: www.example.com\r\n" |
| 11258 | "Proxy-Connection: keep-alive\r\n" |
| 11259 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11260 | const MockWrite kGetAuthThroughProxy( |
| 11261 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11262 | "Host: www.example.com\r\n" |
| 11263 | "Proxy-Connection: keep-alive\r\n" |
| 11264 | "Authorization: auth_token\r\n\r\n"); |
| 11265 | const MockWrite kGetAuthWithProxyAuth( |
| 11266 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11267 | "Host: www.example.com\r\n" |
| 11268 | "Proxy-Connection: keep-alive\r\n" |
| 11269 | "Proxy-Authorization: auth_token\r\n" |
| 11270 | "Authorization: auth_token\r\n\r\n"); |
| 11271 | const MockWrite kConnect( |
| 11272 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11273 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11274 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11275 | const MockWrite kConnectProxyAuth( |
| 11276 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11277 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11278 | "Proxy-Connection: keep-alive\r\n" |
| 11279 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11280 | |
| 11281 | const MockRead kSuccess( |
| 11282 | "HTTP/1.1 200 OK\r\n" |
| 11283 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11284 | "Content-Length: 3\r\n\r\n" |
| 11285 | "Yes"); |
| 11286 | const MockRead kFailure( |
| 11287 | "Should not be called."); |
| 11288 | const MockRead kServerChallenge( |
| 11289 | "HTTP/1.1 401 Unauthorized\r\n" |
| 11290 | "WWW-Authenticate: Mock realm=server\r\n" |
| 11291 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11292 | "Content-Length: 14\r\n\r\n" |
| 11293 | "Unauthorized\r\n"); |
| 11294 | const MockRead kProxyChallenge( |
| 11295 | "HTTP/1.1 407 Unauthorized\r\n" |
| 11296 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 11297 | "Proxy-Connection: close\r\n" |
| 11298 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11299 | "Content-Length: 14\r\n\r\n" |
| 11300 | "Unauthorized\r\n"); |
| 11301 | const MockRead kProxyConnected( |
| 11302 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 11303 | |
| 11304 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 11305 | // no constructors, but the C++ compiler on Windows warns about |
| 11306 | // unspecified data in compound literals. So, moved to using constructors, |
| 11307 | // and TestRound's created with the default constructor should not be used. |
| 11308 | struct TestRound { |
| 11309 | TestRound() |
| 11310 | : expected_rv(ERR_UNEXPECTED), |
| 11311 | extra_write(NULL), |
| 11312 | extra_read(NULL) { |
| 11313 | } |
| 11314 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11315 | int expected_rv_arg) |
| 11316 | : write(write_arg), |
| 11317 | read(read_arg), |
| 11318 | expected_rv(expected_rv_arg), |
| 11319 | extra_write(NULL), |
| 11320 | extra_read(NULL) { |
| 11321 | } |
| 11322 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11323 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 11324 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11325 | : write(write_arg), |
| 11326 | read(read_arg), |
| 11327 | expected_rv(expected_rv_arg), |
| 11328 | extra_write(extra_write_arg), |
| 11329 | extra_read(extra_read_arg) { |
| 11330 | } |
| 11331 | MockWrite write; |
| 11332 | MockRead read; |
| 11333 | int expected_rv; |
| 11334 | const MockWrite* extra_write; |
| 11335 | const MockRead* extra_read; |
| 11336 | }; |
| 11337 | |
| 11338 | static const int kNoSSL = 500; |
| 11339 | |
| 11340 | struct TestConfig { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11341 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11342 | AuthTiming proxy_auth_timing; |
| 11343 | int proxy_auth_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11344 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11345 | AuthTiming server_auth_timing; |
| 11346 | int server_auth_rv; |
| 11347 | int num_auth_rounds; |
| 11348 | int first_ssl_round; |
| 11349 | TestRound rounds[3]; |
| 11350 | } test_configs[] = { |
| 11351 | // Non-authenticating HTTP server with a direct connection. |
| 11352 | { NULL, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 11353 | { TestRound(kGet, kSuccess, OK)}}, |
| 11354 | // Authenticating HTTP server with a direct connection. |
| 11355 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 11356 | { TestRound(kGet, kServerChallenge, OK), |
| 11357 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11358 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 11359 | { TestRound(kGet, kServerChallenge, OK), |
| 11360 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11361 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 11362 | { TestRound(kGet, kServerChallenge, OK), |
| 11363 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11364 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 11365 | { TestRound(kGet, kServerChallenge, OK), |
| 11366 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11367 | // Non-authenticating HTTP server through a non-authenticating proxy. |
| 11368 | { kProxy, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 11369 | { TestRound(kGetProxy, kSuccess, OK)}}, |
| 11370 | // Authenticating HTTP server through a non-authenticating proxy. |
| 11371 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 11372 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 11373 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 11374 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 11375 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 11376 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 11377 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 11378 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 11379 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 11380 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 11381 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 11382 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 11383 | // Non-authenticating HTTP server through an authenticating proxy. |
| 11384 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11385 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11386 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 11387 | { kProxy, AUTH_SYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11388 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11389 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 11390 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11391 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11392 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 11393 | { kProxy, AUTH_ASYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11394 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11395 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 11396 | // Authenticating HTTP server through an authenticating proxy. |
| 11397 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 11398 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11399 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11400 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11401 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 11402 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11403 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11404 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11405 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 11406 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11407 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11408 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11409 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 11410 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11411 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11412 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11413 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 11414 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11415 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11416 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11417 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 11418 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11419 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11420 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11421 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 11422 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11423 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11424 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11425 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 11426 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11427 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11428 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11429 | // Non-authenticating HTTPS server with a direct connection. |
| 11430 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 11431 | { TestRound(kGet, kSuccess, OK)}}, |
| 11432 | // Authenticating HTTPS server with a direct connection. |
| 11433 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 11434 | { TestRound(kGet, kServerChallenge, OK), |
| 11435 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11436 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 11437 | { TestRound(kGet, kServerChallenge, OK), |
| 11438 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11439 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 11440 | { TestRound(kGet, kServerChallenge, OK), |
| 11441 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11442 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 11443 | { TestRound(kGet, kServerChallenge, OK), |
| 11444 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11445 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
| 11446 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 11447 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11448 | // Authenticating HTTPS server through a non-authenticating proxy. |
| 11449 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 11450 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11451 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11452 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 11453 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11454 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11455 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 11456 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11457 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11458 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 11459 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11460 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11461 | // Non-Authenticating HTTPS server through an authenticating proxy. |
| 11462 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 11463 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11464 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11465 | { kProxy, AUTH_SYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11466 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11467 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 11468 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 11469 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11470 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11471 | { kProxy, AUTH_ASYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11472 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11473 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 11474 | // Authenticating HTTPS server through an authenticating proxy. |
| 11475 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 11476 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11477 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11478 | &kGet, &kServerChallenge), |
| 11479 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11480 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 11481 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11482 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11483 | &kGet, &kServerChallenge), |
| 11484 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11485 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 11486 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11487 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11488 | &kGet, &kServerChallenge), |
| 11489 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11490 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 11491 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11492 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11493 | &kGet, &kServerChallenge), |
| 11494 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11495 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 11496 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11497 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11498 | &kGet, &kServerChallenge), |
| 11499 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11500 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 11501 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11502 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11503 | &kGet, &kServerChallenge), |
| 11504 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11505 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 11506 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11507 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11508 | &kGet, &kServerChallenge), |
| 11509 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11510 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 11511 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11512 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11513 | &kGet, &kServerChallenge), |
| 11514 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11515 | }; |
| 11516 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 11517 | for (size_t i = 0; i < arraysize(test_configs); ++i) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11518 | HttpAuthHandlerMock::Factory* auth_factory( |
| 11519 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11520 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 11521 | SSLInfo empty_ssl_info; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11522 | const TestConfig& test_config = test_configs[i]; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 11523 | |
| 11524 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11525 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11526 | for (int n = 0; n < 2; n++) { |
| 11527 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 11528 | std::string auth_challenge = "Mock realm=proxy"; |
| 11529 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 11530 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 11531 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11532 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 11533 | empty_ssl_info, origin, BoundNetLog()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11534 | auth_handler->SetGenerateExpectation( |
| 11535 | test_config.proxy_auth_timing == AUTH_ASYNC, |
| 11536 | test_config.proxy_auth_rv); |
| 11537 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 11538 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11539 | } |
| 11540 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 11541 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11542 | std::string auth_challenge = "Mock realm=server"; |
| 11543 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 11544 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 11545 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11546 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 11547 | empty_ssl_info, origin, BoundNetLog()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11548 | auth_handler->SetGenerateExpectation( |
| 11549 | test_config.server_auth_timing == AUTH_ASYNC, |
| 11550 | test_config.server_auth_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11551 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11552 | } |
| 11553 | if (test_config.proxy_url) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11554 | session_deps_.proxy_service = |
| 11555 | ProxyService::CreateFixed(test_config.proxy_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11556 | } else { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11557 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11558 | } |
| 11559 | |
| 11560 | HttpRequestInfo request; |
| 11561 | request.method = "GET"; |
| 11562 | request.url = GURL(test_config.server_url); |
| 11563 | request.load_flags = 0; |
| 11564 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11565 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11566 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11567 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 11568 | |
| 11569 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 11570 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11571 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 11572 | const TestRound& read_write_round = test_config.rounds[round]; |
| 11573 | |
| 11574 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11575 | mock_reads.back().push_back(read_write_round.read); |
| 11576 | mock_writes.back().push_back(read_write_round.write); |
| 11577 | |
| 11578 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 11579 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 11580 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11581 | mock_reads.push_back(std::vector<MockRead>()); |
| 11582 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11583 | } |
| 11584 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11585 | if (read_write_round.extra_read) { |
| 11586 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11587 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11588 | if (read_write_round.extra_write) { |
| 11589 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 11590 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11591 | |
| 11592 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11593 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11594 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11595 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11596 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11597 | |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 11598 | std::vector<scoped_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11599 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 11600 | data_providers.push_back(make_scoped_ptr(new StaticSocketDataProvider( |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 11601 | mock_reads[i].data(), mock_reads[i].size(), mock_writes[i].data(), |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 11602 | mock_writes[i].size()))); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11603 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 11604 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11605 | } |
| 11606 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11607 | // Transaction must be created after DataProviders, so it's destroyed before |
| 11608 | // they are as well. |
| 11609 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11610 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11611 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 11612 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11613 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11614 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11615 | int rv; |
| 11616 | if (round == 0) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11617 | rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11618 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11619 | rv = trans.RestartWithAuth( |
| 11620 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11621 | } |
| 11622 | if (rv == ERR_IO_PENDING) |
| 11623 | rv = callback.WaitForResult(); |
| 11624 | |
| 11625 | // Compare results with expected data. |
| 11626 | EXPECT_EQ(read_write_round.expected_rv, rv); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11627 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 11628 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11629 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 11630 | continue; |
| 11631 | } |
| 11632 | if (round + 1 < test_config.num_auth_rounds) { |
| 11633 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 11634 | } else { |
| 11635 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 11636 | } |
| 11637 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 11638 | } |
| 11639 | } |
| 11640 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11641 | TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11642 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11643 | HttpAuthHandlerMock::Factory* auth_factory( |
| 11644 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11645 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11646 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11647 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 11648 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11649 | |
| 11650 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 11651 | auth_handler->set_connection_based(true); |
| 11652 | std::string auth_challenge = "Mock realm=server"; |
| 11653 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 11654 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 11655 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 11656 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11657 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 11658 | empty_ssl_info, origin, BoundNetLog()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11659 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11660 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11661 | int rv = OK; |
| 11662 | const HttpResponseInfo* response = NULL; |
| 11663 | HttpRequestInfo request; |
| 11664 | request.method = "GET"; |
| 11665 | request.url = origin; |
| 11666 | request.load_flags = 0; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11667 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11668 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11669 | |
| 11670 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 11671 | // to validate that the TCP socket is not released to the pool between |
| 11672 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11673 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11674 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11675 | 50, // Max sockets for pool |
| 11676 | 1, // Max sockets per group |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11677 | session_deps_.host_resolver.get(), |
| 11678 | session_deps_.socket_factory.get(), |
| 11679 | session_deps_.net_log); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 11680 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 11681 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 11682 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11683 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11684 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11685 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11686 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11687 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11688 | |
| 11689 | const MockWrite kGet( |
| 11690 | "GET / HTTP/1.1\r\n" |
| 11691 | "Host: www.example.com\r\n" |
| 11692 | "Connection: keep-alive\r\n\r\n"); |
| 11693 | const MockWrite kGetAuth( |
| 11694 | "GET / HTTP/1.1\r\n" |
| 11695 | "Host: www.example.com\r\n" |
| 11696 | "Connection: keep-alive\r\n" |
| 11697 | "Authorization: auth_token\r\n\r\n"); |
| 11698 | |
| 11699 | const MockRead kServerChallenge( |
| 11700 | "HTTP/1.1 401 Unauthorized\r\n" |
| 11701 | "WWW-Authenticate: Mock realm=server\r\n" |
| 11702 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11703 | "Content-Length: 14\r\n\r\n" |
| 11704 | "Unauthorized\r\n"); |
| 11705 | const MockRead kSuccess( |
| 11706 | "HTTP/1.1 200 OK\r\n" |
| 11707 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11708 | "Content-Length: 3\r\n\r\n" |
| 11709 | "Yes"); |
| 11710 | |
| 11711 | MockWrite writes[] = { |
| 11712 | // First round |
| 11713 | kGet, |
| 11714 | // Second round |
| 11715 | kGetAuth, |
| 11716 | // Third round |
| 11717 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11718 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11719 | kGetAuth, |
| 11720 | // Competing request |
| 11721 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11722 | }; |
| 11723 | MockRead reads[] = { |
| 11724 | // First round |
| 11725 | kServerChallenge, |
| 11726 | // Second round |
| 11727 | kServerChallenge, |
| 11728 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11729 | kServerChallenge, |
| 11730 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11731 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11732 | // Competing response |
| 11733 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11734 | }; |
| 11735 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 11736 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11737 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11738 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11739 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11740 | |
| 11741 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11742 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11743 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11744 | if (rv == ERR_IO_PENDING) |
| 11745 | rv = callback.WaitForResult(); |
| 11746 | EXPECT_EQ(OK, rv); |
| 11747 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11748 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11749 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11750 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11751 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11752 | // In between rounds, another request comes in for the same domain. |
| 11753 | // It should not be able to grab the TCP socket that trans has already |
| 11754 | // claimed. |
| 11755 | scoped_ptr<HttpTransaction> trans_compete( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11756 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11757 | TestCompletionCallback callback_compete; |
| 11758 | rv = trans_compete->Start( |
| 11759 | &request, callback_compete.callback(), BoundNetLog()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11760 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11761 | // callback_compete.WaitForResult at this point would stall forever, |
| 11762 | // since the HttpNetworkTransaction does not release the request back to |
| 11763 | // the pool until after authentication completes. |
| 11764 | |
| 11765 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11766 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11767 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11768 | if (rv == ERR_IO_PENDING) |
| 11769 | rv = callback.WaitForResult(); |
| 11770 | EXPECT_EQ(OK, rv); |
| 11771 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11772 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11773 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11774 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11775 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11776 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11777 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11778 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11779 | if (rv == ERR_IO_PENDING) |
| 11780 | rv = callback.WaitForResult(); |
| 11781 | EXPECT_EQ(OK, rv); |
| 11782 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11783 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11784 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11785 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11786 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11787 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11788 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11789 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11790 | if (rv == ERR_IO_PENDING) |
| 11791 | rv = callback.WaitForResult(); |
| 11792 | EXPECT_EQ(OK, rv); |
| 11793 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11794 | ASSERT_TRUE(response != NULL); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11795 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11796 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11797 | |
| 11798 | // Read the body since the fourth round was successful. This will also |
| 11799 | // release the socket back to the pool. |
| 11800 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11801 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11802 | if (rv == ERR_IO_PENDING) |
| 11803 | rv = callback.WaitForResult(); |
| 11804 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11805 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11806 | EXPECT_EQ(0, rv); |
| 11807 | // There are still 0 idle sockets, since the trans_compete transaction |
| 11808 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11809 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11810 | |
| 11811 | // The competing request can now finish. Wait for the headers and then |
| 11812 | // read the body. |
| 11813 | rv = callback_compete.WaitForResult(); |
| 11814 | EXPECT_EQ(OK, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11815 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11816 | if (rv == ERR_IO_PENDING) |
| 11817 | rv = callback.WaitForResult(); |
| 11818 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11819 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11820 | EXPECT_EQ(0, rv); |
| 11821 | |
| 11822 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11823 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11824 | } |
| 11825 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11826 | // This tests the case that a request is issued via http instead of spdy after |
| 11827 | // npn is negotiated. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11828 | TEST_P(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 11829 | session_deps_.parse_alternative_services = true; |
| 11830 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11831 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11832 | HttpRequestInfo request; |
| 11833 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11834 | request.url = GURL("https://www.example.org/"); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11835 | request.load_flags = 0; |
| 11836 | |
| 11837 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11838 | MockWrite( |
| 11839 | "GET / HTTP/1.1\r\n" |
| 11840 | "Host: www.example.org\r\n" |
| 11841 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11842 | }; |
| 11843 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 11844 | std::string alternate_protocol_http_header = |
| 11845 | GetAlternateProtocolHttpHeader(); |
| 11846 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11847 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11848 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11849 | MockRead(alternate_protocol_http_header.c_str()), |
| 11850 | MockRead("\r\n"), |
| 11851 | MockRead("hello world"), |
| 11852 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11853 | }; |
| 11854 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11855 | SSLSocketDataProvider ssl(ASYNC, OK); |
davidben | 6974bf7 | 2015-04-27 17:52:48 | [diff] [blame] | 11856 | ssl.SetNextProto(kProtoHTTP11); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11857 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11858 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11859 | |
| 11860 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 11861 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11862 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11863 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11864 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11865 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11866 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11867 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11868 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11869 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11870 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11871 | |
| 11872 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11873 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11874 | |
| 11875 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11876 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11877 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11878 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11879 | |
| 11880 | std::string response_data; |
| 11881 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11882 | EXPECT_EQ("hello world", response_data); |
| 11883 | |
| 11884 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 11885 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11886 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11887 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11888 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 11889 | // immediate server closing of the socket. |
| 11890 | // Regression test for https://crbug.com/46369. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11891 | TEST_P(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 11892 | session_deps_.parse_alternative_services = true; |
| 11893 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11894 | |
| 11895 | HttpRequestInfo request; |
| 11896 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11897 | request.url = GURL("https://www.example.org/"); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11898 | request.load_flags = 0; |
| 11899 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11900 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 11901 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11902 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11903 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 11904 | scoped_ptr<SpdySerializedFrame> req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 11905 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11906 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11907 | |
| 11908 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11909 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11910 | }; |
| 11911 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11912 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11913 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11914 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11915 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11916 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11917 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11918 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11919 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11920 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11921 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11922 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11923 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11924 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11925 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 11926 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11927 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 11928 | // it gets it. This is needed since the auth handler may get destroyed |
| 11929 | // before we get a chance to query it. |
| 11930 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 11931 | public: |
| 11932 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 11933 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11934 | ~UrlRecordingHttpAuthHandlerMock() override {} |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11935 | |
| 11936 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11937 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 11938 | const HttpRequestInfo* request, |
| 11939 | const CompletionCallback& callback, |
| 11940 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11941 | *url_ = request->url; |
| 11942 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 11943 | credentials, request, callback, auth_token); |
| 11944 | } |
| 11945 | |
| 11946 | private: |
| 11947 | GURL* url_; |
| 11948 | }; |
| 11949 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11950 | // This test ensures that the URL passed into the proxy is upgraded to https |
| 11951 | // when doing an Alternate Protocol upgrade. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11952 | TEST_P(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) { |
rch | 3f4b845 | 2016-02-23 16:59:32 | [diff] [blame] | 11953 | session_deps_.parse_alternative_services = false; |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 11954 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11955 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11956 | session_deps_.proxy_service = |
| 11957 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11958 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11959 | session_deps_.net_log = &net_log; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11960 | GURL request_url; |
| 11961 | { |
| 11962 | HttpAuthHandlerMock::Factory* auth_factory = |
| 11963 | new HttpAuthHandlerMock::Factory(); |
| 11964 | UrlRecordingHttpAuthHandlerMock* auth_handler = |
| 11965 | new UrlRecordingHttpAuthHandlerMock(&request_url); |
| 11966 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 11967 | auth_factory->set_do_init_from_challenge(true); |
| 11968 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
| 11969 | } |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11970 | |
| 11971 | HttpRequestInfo request; |
| 11972 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11973 | request.url = GURL("http://www.example.org"); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11974 | request.load_flags = 0; |
| 11975 | |
| 11976 | // First round goes unauthenticated through the proxy. |
| 11977 | MockWrite data_writes_1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11978 | MockWrite( |
| 11979 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 11980 | "Host: www.example.org\r\n" |
| 11981 | "Proxy-Connection: keep-alive\r\n" |
| 11982 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11983 | }; |
| 11984 | MockRead data_reads_1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11985 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 11986 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11987 | MockRead("Alternate-Protocol: 443:"), |
| 11988 | MockRead(GetAlternateProtocolFromParam()), |
| 11989 | MockRead("\r\n"), |
| 11990 | MockRead("Proxy-Connection: close\r\n"), |
| 11991 | MockRead("\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11992 | }; |
| 11993 | StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1), |
| 11994 | data_writes_1, arraysize(data_writes_1)); |
| 11995 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11996 | // Second round tries to tunnel to www.example.org due to the |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11997 | // Alternate-Protocol announcement in the first round. It fails due |
| 11998 | // to a proxy authentication challenge. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11999 | // After the failure, a tunnel is established to www.example.org using |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 12000 | // Proxy-Authorization headers. There is then a SPDY request round. |
| 12001 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 12002 | // NOTE: Despite the "Proxy-Connection: Close", these are done on the |
| 12003 | // same MockTCPClientSocket since the underlying HttpNetworkClientSocket |
| 12004 | // does a Disconnect and Connect on the same socket, rather than trying |
| 12005 | // to obtain a new one. |
| 12006 | // |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 12007 | // NOTE: Originally, the proxy response to the second CONNECT request |
| 12008 | // simply returned another 407 so the unit test could skip the SSL connection |
| 12009 | // establishment and SPDY framing issues. Alas, the |
| 12010 | // retry-http-when-alternate-protocol fails logic kicks in, which was more |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12011 | // complicated to set up expectations for than the SPDY session. |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 12012 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 12013 | scoped_ptr<SpdySerializedFrame> req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12014 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 12015 | scoped_ptr<SpdySerializedFrame> resp( |
| 12016 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12017 | scoped_ptr<SpdySerializedFrame> data( |
| 12018 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12019 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 12020 | MockWrite data_writes_2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12021 | // First connection attempt without Proxy-Authorization. |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12022 | MockWrite(ASYNC, 0, |
| 12023 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12024 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12025 | "Proxy-Connection: keep-alive\r\n" |
| 12026 | "\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 12027 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12028 | // Second connection attempt with Proxy-Authorization. |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12029 | MockWrite(ASYNC, 2, |
| 12030 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12031 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12032 | "Proxy-Connection: keep-alive\r\n" |
| 12033 | "Proxy-Authorization: auth_token\r\n" |
| 12034 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12035 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12036 | // SPDY request |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12037 | CreateMockWrite(*req, 4), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12038 | }; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 12039 | MockRead data_reads_2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12040 | // First connection attempt fails |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 12041 | MockRead(ASYNC, 1, |
| 12042 | "HTTP/1.1 407 Unauthorized\r\n" |
| 12043 | "Proxy-Authenticate: Mock\r\n" |
| 12044 | "Content-Length: 0\r\n" |
| 12045 | "Proxy-Connection: keep-alive\r\n" |
| 12046 | "\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 12047 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12048 | // Second connection attempt passes |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 12049 | MockRead(ASYNC, 3, "HTTP/1.1 200 Connected\r\n\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 12050 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12051 | // SPDY response |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 12052 | CreateMockRead(*resp.get(), 5), CreateMockRead(*data.get(), 6), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12053 | MockRead(ASYNC, 0, 0, 7), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 12054 | }; |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12055 | SequencedSocketData data_2(data_reads_2, arraysize(data_reads_2), |
| 12056 | data_writes_2, arraysize(data_writes_2)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12057 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12058 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12059 | ssl.SetNextProto(GetProtocol()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12060 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 12061 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12062 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12063 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12064 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 12065 | NULL, 0, NULL, 0); |
| 12066 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 12067 | never_finishing_connect); |
| 12068 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12069 | session_deps_.socket_factory->AddSocketDataProvider(&data_1); |
| 12070 | session_deps_.socket_factory->AddSocketDataProvider(&data_2); |
| 12071 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12072 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12073 | &hanging_non_alternate_protocol_socket); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12074 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12075 | |
| 12076 | // First round should work and provide the Alternate-Protocol state. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12077 | TestCompletionCallback callback_1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12078 | scoped_ptr<HttpTransaction> trans_1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12079 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12080 | int rv = trans_1->Start(&request, callback_1.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12081 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12082 | EXPECT_EQ(OK, callback_1.WaitForResult()); |
| 12083 | |
| 12084 | // Second round should attempt a tunnel connect and get an auth challenge. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12085 | TestCompletionCallback callback_2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12086 | scoped_ptr<HttpTransaction> trans_2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12087 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12088 | rv = trans_2->Start(&request, callback_2.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12089 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12090 | EXPECT_EQ(OK, callback_2.WaitForResult()); |
| 12091 | const HttpResponseInfo* response = trans_2->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 12092 | ASSERT_TRUE(response != NULL); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12093 | ASSERT_FALSE(response->auth_challenge.get() == NULL); |
| 12094 | |
| 12095 | // Restart with auth. Tunnel should work and response received. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12096 | TestCompletionCallback callback_3; |
| 12097 | rv = trans_2->RestartWithAuth( |
| 12098 | AuthCredentials(kFoo, kBar), callback_3.callback()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12099 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12100 | EXPECT_EQ(OK, callback_3.WaitForResult()); |
| 12101 | |
| 12102 | // After all that work, these two lines (or actually, just the scheme) are |
| 12103 | // what this test is all about. Make sure it happens correctly. |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12104 | EXPECT_EQ("https", request_url.scheme()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12105 | EXPECT_EQ("www.example.org", request_url.host()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12106 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12107 | LoadTimingInfo load_timing_info; |
| 12108 | EXPECT_TRUE(trans_2->GetLoadTimingInfo(&load_timing_info)); |
| 12109 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12110 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12111 | } |
| 12112 | |
| 12113 | // Test that if we cancel the transaction as the connection is completing, that |
| 12114 | // everything tears down correctly. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12115 | TEST_P(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12116 | // Setup everything about the connection to complete synchronously, so that |
| 12117 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 12118 | // for is the callback from the HttpStreamRequest. |
| 12119 | // Then cancel the transaction. |
| 12120 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12121 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12122 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12123 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 12124 | MockRead(SYNCHRONOUS, "hello world"), |
| 12125 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12126 | }; |
| 12127 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12128 | HttpRequestInfo request; |
| 12129 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12130 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12131 | request.load_flags = 0; |
| 12132 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12133 | session_deps_.host_resolver->set_synchronous_mode(true); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12134 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12135 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12136 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12137 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12138 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 12139 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12140 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12141 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12142 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12143 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12144 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12145 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12146 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12147 | trans.reset(); // Cancel the transaction here. |
| 12148 | |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12149 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12150 | } |
| 12151 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12152 | // Test that if a transaction is cancelled after receiving the headers, the |
| 12153 | // stream is drained properly and added back to the socket pool. The main |
| 12154 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 12155 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 12156 | // deleted. |
| 12157 | // See http://crbug.com/368418 |
| 12158 | TEST_P(HttpNetworkTransactionTest, CancelAfterHeaders) { |
| 12159 | MockRead data_reads[] = { |
| 12160 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 12161 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 12162 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 12163 | MockRead(ASYNC, "1"), |
| 12164 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 12165 | // HttpNetworkTransaction has been deleted. |
| 12166 | MockRead(ASYNC, "2"), |
| 12167 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 12168 | }; |
| 12169 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 12170 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12171 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12172 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12173 | |
| 12174 | { |
| 12175 | HttpRequestInfo request; |
| 12176 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12177 | request.url = GURL("http://www.example.org/"); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12178 | request.load_flags = 0; |
| 12179 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12180 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12181 | TestCompletionCallback callback; |
| 12182 | |
| 12183 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
| 12184 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12185 | callback.WaitForResult(); |
| 12186 | |
| 12187 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 12188 | ASSERT_TRUE(response != NULL); |
| 12189 | EXPECT_TRUE(response->headers.get() != NULL); |
| 12190 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12191 | |
| 12192 | // The transaction and HttpRequestInfo are deleted. |
| 12193 | } |
| 12194 | |
| 12195 | // Let the HttpResponseBodyDrainer drain the socket. |
| 12196 | base::MessageLoop::current()->RunUntilIdle(); |
| 12197 | |
| 12198 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12199 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12200 | } |
| 12201 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12202 | // Test a basic GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12203 | TEST_P(HttpNetworkTransactionTest, ProxyGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12204 | session_deps_.proxy_service = |
| 12205 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12206 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12207 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12208 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12209 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12210 | HttpRequestInfo request; |
| 12211 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12212 | request.url = GURL("http://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12213 | |
| 12214 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12215 | MockWrite( |
| 12216 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 12217 | "Host: www.example.org\r\n" |
| 12218 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12219 | }; |
| 12220 | |
| 12221 | MockRead data_reads1[] = { |
| 12222 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12223 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12224 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12225 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12226 | }; |
| 12227 | |
| 12228 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12229 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12230 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12231 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12232 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12233 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12234 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12235 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 12236 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 12237 | trans->SetBeforeProxyHeadersSentCallback( |
| 12238 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 12239 | base::Unretained(&proxy_headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12240 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12241 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12242 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12243 | |
| 12244 | rv = callback1.WaitForResult(); |
| 12245 | EXPECT_EQ(OK, rv); |
| 12246 | |
| 12247 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 12248 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12249 | |
| 12250 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12251 | EXPECT_EQ(200, response->headers->response_code()); |
| 12252 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12253 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 12254 | EXPECT_TRUE( |
| 12255 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 12256 | EXPECT_TRUE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
| 12257 | EXPECT_EQ("myproxy:70", proxy_headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12258 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12259 | |
| 12260 | LoadTimingInfo load_timing_info; |
| 12261 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 12262 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12263 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12264 | } |
| 12265 | |
| 12266 | // Test a basic HTTPS GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12267 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12268 | session_deps_.proxy_service = |
| 12269 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12270 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12271 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12272 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12273 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12274 | HttpRequestInfo request; |
| 12275 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12276 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12277 | |
| 12278 | // Since we have proxy, should try to establish tunnel. |
| 12279 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12280 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12281 | "Host: www.example.org:443\r\n" |
| 12282 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12283 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12284 | MockWrite("GET / HTTP/1.1\r\n" |
| 12285 | "Host: www.example.org\r\n" |
| 12286 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12287 | }; |
| 12288 | |
| 12289 | MockRead data_reads1[] = { |
| 12290 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 12291 | |
| 12292 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12293 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12294 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12295 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12296 | }; |
| 12297 | |
| 12298 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12299 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12300 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12301 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12302 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12303 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12304 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12305 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12306 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12307 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12308 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12309 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12310 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12311 | |
| 12312 | rv = callback1.WaitForResult(); |
| 12313 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 12314 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12315 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12316 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12317 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12318 | NetLog::PHASE_NONE); |
| 12319 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12320 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12321 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12322 | NetLog::PHASE_NONE); |
| 12323 | |
| 12324 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 12325 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12326 | |
| 12327 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12328 | EXPECT_EQ(200, response->headers->response_code()); |
| 12329 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12330 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 12331 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 12332 | EXPECT_TRUE( |
| 12333 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12334 | |
| 12335 | LoadTimingInfo load_timing_info; |
| 12336 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 12337 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12338 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12339 | } |
| 12340 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12341 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 12342 | // literal host. |
| 12343 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
| 12344 | session_deps_.proxy_service = |
| 12345 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 12346 | BoundTestNetLog log; |
| 12347 | session_deps_.net_log = log.bound().net_log(); |
| 12348 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12349 | |
| 12350 | HttpRequestInfo request; |
| 12351 | request.method = "GET"; |
| 12352 | request.url = GURL("https://[::1]:443/"); |
| 12353 | |
| 12354 | // Since we have proxy, should try to establish tunnel. |
| 12355 | MockWrite data_writes1[] = { |
| 12356 | MockWrite("CONNECT [::1]:443 HTTP/1.1\r\n" |
| 12357 | "Host: [::1]:443\r\n" |
| 12358 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 12359 | |
| 12360 | MockWrite("GET / HTTP/1.1\r\n" |
| 12361 | "Host: [::1]\r\n" |
| 12362 | "Connection: keep-alive\r\n\r\n"), |
| 12363 | }; |
| 12364 | |
| 12365 | MockRead data_reads1[] = { |
| 12366 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 12367 | |
| 12368 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12369 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12370 | MockRead("Content-Length: 100\r\n\r\n"), |
| 12371 | MockRead(SYNCHRONOUS, OK), |
| 12372 | }; |
| 12373 | |
| 12374 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12375 | data_writes1, arraysize(data_writes1)); |
| 12376 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 12377 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12378 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12379 | |
| 12380 | TestCompletionCallback callback1; |
| 12381 | |
| 12382 | scoped_ptr<HttpTransaction> trans( |
| 12383 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12384 | |
| 12385 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 12386 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12387 | |
| 12388 | rv = callback1.WaitForResult(); |
| 12389 | EXPECT_EQ(OK, rv); |
| 12390 | TestNetLogEntry::List entries; |
| 12391 | log.GetEntries(&entries); |
| 12392 | size_t pos = ExpectLogContainsSomewhere( |
| 12393 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 12394 | NetLog::PHASE_NONE); |
| 12395 | ExpectLogContainsSomewhere( |
| 12396 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12397 | NetLog::PHASE_NONE); |
| 12398 | |
| 12399 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 12400 | ASSERT_TRUE(response != NULL); |
| 12401 | |
| 12402 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12403 | EXPECT_EQ(200, response->headers->response_code()); |
| 12404 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12405 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 12406 | EXPECT_TRUE(response->was_fetched_via_proxy); |
| 12407 | EXPECT_TRUE( |
| 12408 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
| 12409 | |
| 12410 | LoadTimingInfo load_timing_info; |
| 12411 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 12412 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12413 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 12414 | } |
| 12415 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12416 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 12417 | // while establishing the tunnel. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12418 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12419 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12420 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12421 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12422 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12423 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12424 | HttpRequestInfo request; |
| 12425 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12426 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12427 | |
| 12428 | // Since we have proxy, should try to establish tunnel. |
| 12429 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12430 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12431 | "Host: www.example.org:443\r\n" |
| 12432 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12433 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12434 | MockWrite("GET / HTTP/1.1\r\n" |
| 12435 | "Host: www.example.org\r\n" |
| 12436 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12437 | }; |
| 12438 | |
| 12439 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12440 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12441 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12442 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12443 | }; |
| 12444 | |
| 12445 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12446 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12447 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12448 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12449 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12450 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12451 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12452 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12453 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12454 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12455 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12456 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12457 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12458 | |
| 12459 | rv = callback1.WaitForResult(); |
| 12460 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 12461 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12462 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12463 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12464 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12465 | NetLog::PHASE_NONE); |
| 12466 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12467 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12468 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12469 | NetLog::PHASE_NONE); |
| 12470 | } |
| 12471 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12472 | // Test for crbug.com/55424. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12473 | TEST_P(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 12474 | scoped_ptr<SpdySerializedFrame> req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12475 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12476 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12477 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 12478 | scoped_ptr<SpdySerializedFrame> resp( |
| 12479 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12480 | scoped_ptr<SpdySerializedFrame> data( |
| 12481 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12482 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12483 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12484 | }; |
| 12485 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12486 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12487 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12488 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12489 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12490 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12491 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12492 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12493 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12494 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12495 | |
| 12496 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12497 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12498 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 12499 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12500 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12501 | CreateInsecureSpdySession(session.get(), key, BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12502 | |
| 12503 | HttpRequestInfo request; |
| 12504 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12505 | request.url = GURL("https://www.example.org/"); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12506 | request.load_flags = 0; |
| 12507 | |
| 12508 | // This is the important line that marks this as a preconnect. |
| 12509 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 12510 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12511 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12512 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12513 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12514 | TestCompletionCallback callback; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12515 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12516 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12517 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12518 | } |
| 12519 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12520 | // Given a net error, cause that error to be returned from the first Write() |
| 12521 | // call and verify that the HttpTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12522 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12523 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12524 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12525 | request_info.url = GURL("https://www.example.com/"); |
| 12526 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12527 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12528 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12529 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12530 | MockWrite data_writes[] = { |
| 12531 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12532 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12533 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12534 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12535 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12536 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12537 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12538 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12539 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12540 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12541 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12542 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 12543 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12544 | rv = callback.WaitForResult(); |
| 12545 | ASSERT_EQ(error, rv); |
| 12546 | } |
| 12547 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12548 | TEST_P(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12549 | // Just check a grab bag of cert errors. |
| 12550 | static const int kErrors[] = { |
| 12551 | ERR_CERT_COMMON_NAME_INVALID, |
| 12552 | ERR_CERT_AUTHORITY_INVALID, |
| 12553 | ERR_CERT_DATE_INVALID, |
| 12554 | }; |
| 12555 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12556 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 12557 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12558 | } |
| 12559 | } |
| 12560 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12561 | // Ensure that a client certificate is removed from the SSL client auth |
| 12562 | // cache when: |
| 12563 | // 1) No proxy is involved. |
| 12564 | // 2) TLS False Start is disabled. |
| 12565 | // 3) The initial TLS handshake requests a client certificate. |
| 12566 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12567 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 12568 | ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12569 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12570 | request_info.url = GURL("https://www.example.com/"); |
| 12571 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12572 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12573 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12574 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12575 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12576 | |
| 12577 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 12578 | // CertificateRequest is received for the first time, the handshake will |
| 12579 | // be aborted to allow the caller to provide a certificate. |
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 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 12587 | // False Start is not being used, the result of the SSL handshake will be |
| 12588 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 12589 | // matches the result of a server sending a handshake_failure alert, |
| 12590 | // rather than a Finished message, because it requires a client |
| 12591 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12592 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12593 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12594 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12595 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12596 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12597 | |
| 12598 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 12599 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 12600 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 12601 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12602 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 12603 | // requiring a client certificate, this fallback handshake should also |
| 12604 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12605 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[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(NULL, 0, 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 contains the data for the fourth SSL handshake. When a |
| 12612 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 12613 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 12614 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12615 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 12616 | // requiring a client certificate, this fallback handshake should also |
| 12617 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12618 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12619 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12620 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12621 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12622 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12623 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12624 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12625 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12626 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12627 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12628 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12629 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12630 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 12631 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12632 | |
| 12633 | // Complete the SSL handshake, which should abort due to requiring a |
| 12634 | // client certificate. |
| 12635 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12636 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12637 | |
| 12638 | // Indicate that no certificate should be supplied. From the perspective |
| 12639 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 12640 | // certificate, so this is the same as supply a |
| 12641 | // legitimate-but-unacceptable certificate. |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12642 | rv = trans->RestartWithCertificate(NULL, NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12643 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12644 | |
| 12645 | // Ensure the certificate was added to the client auth cache before |
| 12646 | // allowing the connection to continue restarting. |
| 12647 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12648 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12649 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12650 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12651 | ASSERT_EQ(NULL, client_cert.get()); |
| 12652 | |
| 12653 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12654 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 12655 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12656 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12657 | ASSERT_EQ(ERR_SSL_PROTOCOL_ERROR, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12658 | |
| 12659 | // Ensure that the client certificate is removed from the cache on a |
| 12660 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12661 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12662 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12663 | } |
| 12664 | |
| 12665 | // Ensure that a client certificate is removed from the SSL client auth |
| 12666 | // cache when: |
| 12667 | // 1) No proxy is involved. |
| 12668 | // 2) TLS False Start is enabled. |
| 12669 | // 3) The initial TLS handshake requests a client certificate. |
| 12670 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12671 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 12672 | ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12673 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12674 | request_info.url = GURL("https://www.example.com/"); |
| 12675 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12676 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12677 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12678 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12679 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12680 | |
| 12681 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 12682 | // return successfully after reading up to the peer's Certificate message. |
| 12683 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 12684 | // enqueue application data to be sent in the same packet as the |
| 12685 | // ChangeCipherSpec and Finished messages. |
| 12686 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 12687 | // called, which expects to process the peer's ChangeCipherSpec and |
| 12688 | // Finished messages. If there was an error negotiating with the peer, |
| 12689 | // such as due to the peer requiring a client certificate when none was |
| 12690 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 12691 | // called. |
| 12692 | |
| 12693 | // Like the non-False Start case, when a client certificate is requested by |
| 12694 | // the peer, the handshake is aborted during the Connect() call. |
| 12695 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12696 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12697 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12698 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12699 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12700 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12701 | |
| 12702 | // When a client certificate is supplied, Connect() will not be aborted |
| 12703 | // when the peer requests the certificate. Instead, the handshake will |
| 12704 | // artificially succeed, allowing the caller to write the HTTP request to |
| 12705 | // the socket. The handshake messages are not processed until Read() is |
| 12706 | // called, which then detects that the handshake was aborted, due to the |
| 12707 | // peer sending a handshake_failure because it requires a client |
| 12708 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12709 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12710 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12711 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12712 | MockRead data2_reads[] = { |
| 12713 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12714 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12715 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12716 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12717 | |
| 12718 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12719 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 12720 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12721 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12722 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12723 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12724 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12725 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12726 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12727 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 12728 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12729 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12730 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12731 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12732 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12733 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12734 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 12735 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12736 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 12737 | ssl_data5.cert_request_info = cert_request.get(); |
| 12738 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12739 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 12740 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 12741 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12742 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12743 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12744 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12745 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12746 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12747 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12748 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 12749 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12750 | |
| 12751 | // Complete the SSL handshake, which should abort due to requiring a |
| 12752 | // client certificate. |
| 12753 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12754 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12755 | |
| 12756 | // Indicate that no certificate should be supplied. From the perspective |
| 12757 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 12758 | // certificate, so this is the same as supply a |
| 12759 | // legitimate-but-unacceptable certificate. |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12760 | rv = trans->RestartWithCertificate(NULL, NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12761 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12762 | |
| 12763 | // Ensure the certificate was added to the client auth cache before |
| 12764 | // allowing the connection to continue restarting. |
| 12765 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12766 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12767 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12768 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12769 | ASSERT_EQ(NULL, client_cert.get()); |
| 12770 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12771 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12772 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 12773 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12774 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12775 | ASSERT_EQ(ERR_SSL_PROTOCOL_ERROR, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12776 | |
| 12777 | // Ensure that the client certificate is removed from the cache on a |
| 12778 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12779 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12780 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12781 | } |
| 12782 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12783 | // Ensure that a client certificate is removed from the SSL client auth |
| 12784 | // cache when: |
| 12785 | // 1) An HTTPS proxy is involved. |
| 12786 | // 3) The HTTPS proxy requests a client certificate. |
| 12787 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 12788 | // proxy. |
| 12789 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 12790 | // then for connecting to an HTTP endpoint. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12791 | TEST_P(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12792 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12793 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12794 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12795 | |
| 12796 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12797 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12798 | |
| 12799 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 12800 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 12801 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 12802 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12803 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12804 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12805 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12806 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12807 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12808 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12809 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12810 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12811 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12812 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12813 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12814 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12815 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 12816 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12817 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12818 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12819 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12820 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12821 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12822 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12823 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12824 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12825 | requests[0].url = GURL("https://www.example.com/"); |
| 12826 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12827 | requests[0].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12828 | |
| 12829 | requests[1].url = GURL("http://www.example.com/"); |
| 12830 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12831 | requests[1].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12832 | |
| 12833 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12834 | session_deps_.socket_factory->ResetNextMockIndexes(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12835 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12836 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12837 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12838 | |
| 12839 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12840 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12841 | int rv = trans->Start(&requests[i], callback.callback(), BoundNetLog()); |
| 12842 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12843 | |
| 12844 | // Complete the SSL handshake, which should abort due to requiring a |
| 12845 | // client certificate. |
| 12846 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12847 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12848 | |
| 12849 | // Indicate that no certificate should be supplied. From the perspective |
| 12850 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 12851 | // certificate, so this is the same as supply a |
| 12852 | // legitimate-but-unacceptable certificate. |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12853 | rv = trans->RestartWithCertificate(NULL, NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12854 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12855 | |
| 12856 | // Ensure the certificate was added to the client auth cache before |
| 12857 | // allowing the connection to continue restarting. |
| 12858 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12859 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12860 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12861 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12862 | ASSERT_EQ(NULL, client_cert.get()); |
| 12863 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 12864 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12865 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12866 | HostPortPair("www.example.com", 443), &client_cert, |
| 12867 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12868 | |
| 12869 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 12870 | // then consume ssl_data3, which should also fail. The result code is |
| 12871 | // checked against what ssl_data3 should return. |
| 12872 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12873 | ASSERT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12874 | |
| 12875 | // Now that the new handshake has failed, ensure that the client |
| 12876 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12877 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12878 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12879 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12880 | HostPortPair("www.example.com", 443), &client_cert, |
| 12881 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12882 | } |
| 12883 | } |
| 12884 | |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 12885 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 12886 | session_deps_.parse_alternative_services = true; |
| 12887 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12888 | |
| 12889 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12890 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12891 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 12892 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 12893 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12894 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12895 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12896 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12897 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12898 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 12899 | scoped_ptr<SpdySerializedFrame> host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12900 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12901 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 12902 | scoped_ptr<SpdySerializedFrame> host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12903 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12904 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12905 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12906 | }; |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 12907 | scoped_ptr<SpdySerializedFrame> host1_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12908 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 12909 | scoped_ptr<SpdySerializedFrame> host1_resp_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12910 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 12911 | scoped_ptr<SpdySerializedFrame> host2_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12912 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 12913 | scoped_ptr<SpdySerializedFrame> host2_resp_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12914 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12915 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12916 | CreateMockRead(*host1_resp, 1), |
| 12917 | CreateMockRead(*host1_resp_body, 2), |
| 12918 | CreateMockRead(*host2_resp, 4), |
| 12919 | CreateMockRead(*host2_resp_body, 5), |
| 12920 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12921 | }; |
| 12922 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 12923 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12924 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12925 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 12926 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12927 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12928 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 12929 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12930 | HttpRequestInfo request1; |
| 12931 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12932 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12933 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12934 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12935 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12936 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12937 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12938 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12939 | |
| 12940 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 12941 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12942 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12943 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12944 | |
| 12945 | std::string response_data; |
| 12946 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 12947 | EXPECT_EQ("hello!", response_data); |
| 12948 | |
| 12949 | // Preload www.gmail.com into HostCache. |
| 12950 | HostPortPair host_port("www.gmail.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12951 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12952 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12953 | rv = session_deps_.host_resolver->Resolve(resolve_info, |
| 12954 | DEFAULT_PRIORITY, |
| 12955 | &ignored, |
| 12956 | callback.callback(), |
| 12957 | NULL, |
| 12958 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 12959 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12960 | rv = callback.WaitForResult(); |
| 12961 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12962 | |
| 12963 | HttpRequestInfo request2; |
| 12964 | request2.method = "GET"; |
| 12965 | request2.url = GURL("https://www.gmail.com/"); |
| 12966 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12967 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12968 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12969 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12970 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12971 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12972 | |
| 12973 | response = trans2.GetResponseInfo(); |
| 12974 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12975 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12976 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12977 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12978 | EXPECT_TRUE(response->was_npn_negotiated); |
| 12979 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 12980 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12981 | } |
| 12982 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12983 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 12984 | session_deps_.parse_alternative_services = true; |
| 12985 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12986 | |
| 12987 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12988 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12989 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12990 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 12991 | pool_peer.DisableDomainAuthenticationVerification(); |
| 12992 | |
| 12993 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12994 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12995 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12996 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 12997 | scoped_ptr<SpdySerializedFrame> host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12998 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12999 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 13000 | scoped_ptr<SpdySerializedFrame> host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13001 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13002 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13003 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13004 | }; |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 13005 | scoped_ptr<SpdySerializedFrame> host1_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13006 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 13007 | scoped_ptr<SpdySerializedFrame> host1_resp_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13008 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 13009 | scoped_ptr<SpdySerializedFrame> host2_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13010 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 13011 | scoped_ptr<SpdySerializedFrame> host2_resp_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13012 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13013 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13014 | CreateMockRead(*host1_resp, 1), |
| 13015 | CreateMockRead(*host1_resp_body, 2), |
| 13016 | CreateMockRead(*host2_resp, 4), |
| 13017 | CreateMockRead(*host2_resp_body, 5), |
| 13018 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13019 | }; |
| 13020 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13021 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13022 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13023 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13024 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13025 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13026 | |
| 13027 | TestCompletionCallback callback; |
| 13028 | HttpRequestInfo request1; |
| 13029 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13030 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13031 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13032 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13033 | |
| 13034 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
| 13035 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13036 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 13037 | |
| 13038 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 13039 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13040 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13041 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13042 | |
| 13043 | std::string response_data; |
| 13044 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 13045 | EXPECT_EQ("hello!", response_data); |
| 13046 | |
| 13047 | HttpRequestInfo request2; |
| 13048 | request2.method = "GET"; |
| 13049 | request2.url = GURL("https://www.gmail.com/"); |
| 13050 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13051 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13052 | |
| 13053 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
| 13054 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13055 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 13056 | |
| 13057 | response = trans2.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] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13061 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13062 | EXPECT_TRUE(response->was_npn_negotiated); |
| 13063 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 13064 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13065 | } |
| 13066 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13067 | class OneTimeCachingHostResolver : public HostResolver { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13068 | public: |
| 13069 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
| 13070 | : host_port_(host_port) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13071 | ~OneTimeCachingHostResolver() override {} |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13072 | |
| 13073 | RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); } |
| 13074 | |
| 13075 | // HostResolver methods: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13076 | int Resolve(const RequestInfo& info, |
| 13077 | RequestPriority priority, |
| 13078 | AddressList* addresses, |
| 13079 | const CompletionCallback& callback, |
| 13080 | RequestHandle* out_req, |
| 13081 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 13082 | return host_resolver_.Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 13083 | info, priority, addresses, callback, out_req, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 13084 | } |
| 13085 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13086 | int ResolveFromCache(const RequestInfo& info, |
| 13087 | AddressList* addresses, |
| 13088 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 13089 | int rv = host_resolver_.ResolveFromCache(info, addresses, net_log); |
| 13090 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
[email protected] | 98e1cd01 | 2011-11-08 15:33:09 | [diff] [blame] | 13091 | host_resolver_.GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13092 | return rv; |
| 13093 | } |
| 13094 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13095 | void CancelRequest(RequestHandle req) override { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13096 | host_resolver_.CancelRequest(req); |
| 13097 | } |
| 13098 | |
[email protected] | 46da33be | 2011-07-19 21:58:04 | [diff] [blame] | 13099 | MockCachingHostResolver* GetMockHostResolver() { |
| 13100 | return &host_resolver_; |
| 13101 | } |
| 13102 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13103 | private: |
| 13104 | MockCachingHostResolver host_resolver_; |
| 13105 | const HostPortPair host_port_; |
| 13106 | }; |
| 13107 | |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 13108 | TEST_P(HttpNetworkTransactionTest, |
| 13109 | UseIPConnectionPoolingWithHostCacheExpiration) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 13110 | session_deps_.parse_alternative_services = true; |
| 13111 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13112 | |
| 13113 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13114 | OneTimeCachingHostResolver host_resolver(HostPortPair("www.gmail.com", 443)); |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 13115 | HttpNetworkSession::Params params = |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13116 | SpdySessionDependencies::CreateSessionParams(&session_deps_); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13117 | params.host_resolver = &host_resolver; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13118 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 13119 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 13120 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13121 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13122 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13123 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13124 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13125 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 13126 | scoped_ptr<SpdySerializedFrame> host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13127 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13128 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 13129 | scoped_ptr<SpdySerializedFrame> host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13130 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13131 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13132 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13133 | }; |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 13134 | scoped_ptr<SpdySerializedFrame> host1_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13135 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 13136 | scoped_ptr<SpdySerializedFrame> host1_resp_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13137 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 13138 | scoped_ptr<SpdySerializedFrame> host2_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13139 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 13140 | scoped_ptr<SpdySerializedFrame> host2_resp_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13141 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13142 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13143 | CreateMockRead(*host1_resp, 1), |
| 13144 | CreateMockRead(*host1_resp_body, 2), |
| 13145 | CreateMockRead(*host2_resp, 4), |
| 13146 | CreateMockRead(*host2_resp_body, 5), |
| 13147 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13148 | }; |
| 13149 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13150 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13151 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13152 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13153 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13154 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13155 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 13156 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13157 | HttpRequestInfo request1; |
| 13158 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13159 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13160 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13161 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13162 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13163 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13164 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13165 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13166 | |
| 13167 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 13168 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13169 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13170 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13171 | |
| 13172 | std::string response_data; |
| 13173 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 13174 | EXPECT_EQ("hello!", response_data); |
| 13175 | |
| 13176 | // Preload cache entries into HostCache. |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 13177 | HostResolver::RequestInfo resolve_info(HostPortPair("www.gmail.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13178 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 13179 | rv = host_resolver.Resolve(resolve_info, |
| 13180 | DEFAULT_PRIORITY, |
| 13181 | &ignored, |
| 13182 | callback.callback(), |
| 13183 | NULL, |
| 13184 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 13185 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13186 | rv = callback.WaitForResult(); |
| 13187 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13188 | |
| 13189 | HttpRequestInfo request2; |
| 13190 | request2.method = "GET"; |
| 13191 | request2.url = GURL("https://www.gmail.com/"); |
| 13192 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13193 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13194 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13195 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13196 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13197 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13198 | |
| 13199 | response = trans2.GetResponseInfo(); |
| 13200 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13201 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13202 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13203 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13204 | EXPECT_TRUE(response->was_npn_negotiated); |
| 13205 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 13206 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13207 | } |
| 13208 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13209 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13210 | const std::string https_url = "https://www.example.org:8080/"; |
| 13211 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13212 | |
| 13213 | // SPDY GET for HTTPS URL |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 13214 | scoped_ptr<SpdySerializedFrame> req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13215 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13216 | |
| 13217 | MockWrite writes1[] = { |
| 13218 | CreateMockWrite(*req1, 0), |
| 13219 | }; |
| 13220 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 13221 | scoped_ptr<SpdySerializedFrame> resp1( |
| 13222 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13223 | scoped_ptr<SpdySerializedFrame> body1( |
| 13224 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 13225 | MockRead reads1[] = {CreateMockRead(*resp1, 1), CreateMockRead(*body1, 2), |
| 13226 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13227 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13228 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 13229 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13230 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13231 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13232 | |
| 13233 | // HTTP GET for the HTTP URL |
| 13234 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13235 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13236 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13237 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13238 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13239 | }; |
| 13240 | |
| 13241 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13242 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 13243 | MockRead(ASYNC, 2, "hello"), |
| 13244 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13245 | }; |
| 13246 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13247 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 13248 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13249 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13250 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13251 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13252 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13253 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13254 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13255 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13256 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13257 | |
| 13258 | // Start the first transaction to set up the SpdySession |
| 13259 | HttpRequestInfo request1; |
| 13260 | request1.method = "GET"; |
| 13261 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13262 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13263 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13264 | TestCompletionCallback callback1; |
| 13265 | EXPECT_EQ(ERR_IO_PENDING, |
| 13266 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 13267 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13268 | |
| 13269 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 13270 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 13271 | |
| 13272 | // Now, start the HTTP request |
| 13273 | HttpRequestInfo request2; |
| 13274 | request2.method = "GET"; |
| 13275 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13276 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13277 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13278 | TestCompletionCallback callback2; |
| 13279 | EXPECT_EQ(ERR_IO_PENDING, |
| 13280 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 13281 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13282 | |
| 13283 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 13284 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 13285 | } |
| 13286 | |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13287 | class AltSvcCertificateVerificationTest : public HttpNetworkTransactionTest { |
| 13288 | public: |
| 13289 | void Run(bool pooling, bool valid) { |
| 13290 | HostPortPair origin(valid ? "mail.example.org" : "invalid.example.org", |
| 13291 | 443); |
| 13292 | HostPortPair alternative("www.example.org", 443); |
| 13293 | |
| 13294 | base::FilePath certs_dir = GetTestCertsDirectory(); |
| 13295 | scoped_refptr<X509Certificate> cert( |
| 13296 | ImportCertFromFile(certs_dir, "spdy_pooling.pem")); |
| 13297 | ASSERT_TRUE(cert.get()); |
| 13298 | bool common_name_fallback_used; |
| 13299 | EXPECT_EQ(valid, |
| 13300 | cert->VerifyNameMatch(origin.host(), &common_name_fallback_used)); |
| 13301 | EXPECT_TRUE( |
| 13302 | cert->VerifyNameMatch(alternative.host(), &common_name_fallback_used)); |
| 13303 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13304 | ssl.SetNextProto(GetProtocol()); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13305 | ssl.cert = cert; |
| 13306 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13307 | |
| 13308 | // If pooling, then start a request to alternative first to create a |
| 13309 | // SpdySession. |
| 13310 | std::string url0 = "https://www.example.org:443"; |
| 13311 | // Second request to origin, which has an alternative service, and could |
| 13312 | // open a connection to the alternative host or pool to the existing one. |
| 13313 | std::string url1("https://"); |
| 13314 | url1.append(origin.host()); |
| 13315 | url1.append(":443"); |
| 13316 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 13317 | scoped_ptr<SpdySerializedFrame> req0; |
| 13318 | scoped_ptr<SpdySerializedFrame> req1; |
| 13319 | scoped_ptr<SpdySerializedFrame> resp0; |
| 13320 | scoped_ptr<SpdySerializedFrame> body0; |
| 13321 | scoped_ptr<SpdySerializedFrame> resp1; |
| 13322 | scoped_ptr<SpdySerializedFrame> body1; |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13323 | std::vector<MockWrite> writes; |
| 13324 | std::vector<MockRead> reads; |
| 13325 | |
| 13326 | if (pooling) { |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13327 | req0.reset(spdy_util_.ConstructSpdyGet(url0.c_str(), 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13328 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13329 | req1.reset(spdy_util_.ConstructSpdyGet(url1.c_str(), 3, LOWEST)); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13330 | |
| 13331 | writes.push_back(CreateMockWrite(*req0, 0)); |
| 13332 | writes.push_back(CreateMockWrite(*req1, 3)); |
| 13333 | |
| 13334 | resp0.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13335 | body0.reset(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 13336 | resp1.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 13337 | body1.reset(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
| 13338 | |
| 13339 | reads.push_back(CreateMockRead(*resp0, 1)); |
| 13340 | reads.push_back(CreateMockRead(*body0, 2)); |
| 13341 | reads.push_back(MockRead(ASYNC, ERR_IO_PENDING, 4)); |
| 13342 | reads.push_back(CreateMockRead(*resp1, 5)); |
| 13343 | reads.push_back(CreateMockRead(*body1, 6)); |
| 13344 | reads.push_back(MockRead(ASYNC, OK, 7)); |
| 13345 | } else { |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13346 | req1.reset(spdy_util_.ConstructSpdyGet(url1.c_str(), 1, LOWEST)); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13347 | |
| 13348 | writes.push_back(CreateMockWrite(*req1, 0)); |
| 13349 | |
| 13350 | resp1.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13351 | body1.reset(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 13352 | |
| 13353 | reads.push_back(CreateMockRead(*resp1, 1)); |
| 13354 | reads.push_back(CreateMockRead(*body1, 2)); |
| 13355 | reads.push_back(MockRead(ASYNC, OK, 3)); |
| 13356 | } |
| 13357 | |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 13358 | SequencedSocketData data(reads.data(), reads.size(), writes.data(), |
| 13359 | writes.size()); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13360 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13361 | |
| 13362 | // Connection to the origin fails. |
| 13363 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 13364 | StaticSocketDataProvider data_refused; |
| 13365 | data_refused.set_connect_data(mock_connect); |
| 13366 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13367 | |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 13368 | session_deps_.parse_alternative_services = true; |
| 13369 | session_deps_.enable_alternative_service_with_different_host = true; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13370 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13371 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 13372 | session->http_server_properties(); |
| 13373 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13374 | AlternateProtocolFromNextProto(GetProtocol()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13375 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13376 | http_server_properties->SetAlternativeService(origin, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 13377 | expiration); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13378 | |
| 13379 | // First request to alternative. |
| 13380 | if (pooling) { |
| 13381 | scoped_ptr<HttpTransaction> trans0( |
| 13382 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13383 | HttpRequestInfo request0; |
| 13384 | request0.method = "GET"; |
| 13385 | request0.url = GURL(url0); |
| 13386 | request0.load_flags = 0; |
| 13387 | TestCompletionCallback callback0; |
| 13388 | |
| 13389 | int rv = trans0->Start(&request0, callback0.callback(), BoundNetLog()); |
| 13390 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13391 | rv = callback0.WaitForResult(); |
| 13392 | EXPECT_EQ(OK, rv); |
| 13393 | } |
| 13394 | |
| 13395 | // Second request to origin. |
| 13396 | scoped_ptr<HttpTransaction> trans1( |
| 13397 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13398 | HttpRequestInfo request1; |
| 13399 | request1.method = "GET"; |
| 13400 | request1.url = GURL(url1); |
| 13401 | request1.load_flags = 0; |
| 13402 | TestCompletionCallback callback1; |
| 13403 | |
| 13404 | int rv = trans1->Start(&request1, callback1.callback(), BoundNetLog()); |
| 13405 | EXPECT_EQ(ERR_IO_PENDING, rv); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 13406 | base::MessageLoop::current()->RunUntilIdle(); |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 13407 | if (data.IsPaused()) |
| 13408 | data.Resume(); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13409 | rv = callback1.WaitForResult(); |
| 13410 | if (valid) { |
| 13411 | EXPECT_EQ(OK, rv); |
| 13412 | } else { |
| 13413 | if (pooling) { |
| 13414 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 13415 | } else { |
| 13416 | EXPECT_EQ(ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN, rv); |
| 13417 | } |
| 13418 | } |
| 13419 | } |
| 13420 | }; |
| 13421 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13422 | INSTANTIATE_TEST_CASE_P(ProtoPlusDepend, |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13423 | AltSvcCertificateVerificationTest, |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13424 | testing::Values(kTestCaseSPDY31, |
| 13425 | kTestCaseHTTP2NoPriorityDependencies, |
| 13426 | kTestCaseHTTP2PriorityDependencies)); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13427 | |
| 13428 | // The alternative service host must exhibit a certificate that is valid for the |
| 13429 | // origin host. Test that this is enforced when pooling to an existing |
| 13430 | // connection. |
| 13431 | TEST_P(AltSvcCertificateVerificationTest, PoolingValid) { |
| 13432 | Run(true, true); |
| 13433 | } |
| 13434 | |
| 13435 | TEST_P(AltSvcCertificateVerificationTest, PoolingInvalid) { |
| 13436 | Run(true, false); |
| 13437 | } |
| 13438 | |
| 13439 | // The alternative service host must exhibit a certificate that is valid for the |
| 13440 | // origin host. Test that this is enforced when opening a new connection. |
| 13441 | TEST_P(AltSvcCertificateVerificationTest, NewConnectionValid) { |
| 13442 | Run(false, true); |
| 13443 | } |
| 13444 | |
| 13445 | TEST_P(AltSvcCertificateVerificationTest, NewConnectionInvalid) { |
| 13446 | Run(false, false); |
| 13447 | } |
| 13448 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13449 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 13450 | // with the alternative server. That connection should not be used. |
| 13451 | TEST_P(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
| 13452 | HostPortPair origin("origin.example.org", 443); |
| 13453 | HostPortPair alternative("alternative.example.org", 443); |
| 13454 | |
| 13455 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 13456 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13457 | ssl.SetNextProto(kProtoHTTP11); |
| 13458 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13459 | |
| 13460 | // No data should be read from the alternative, because HTTP/1.1 is |
| 13461 | // negotiated. |
| 13462 | StaticSocketDataProvider data; |
| 13463 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13464 | |
| 13465 | // This test documents that an alternate Job should not be used if HTTP/1.1 is |
| 13466 | // negotiated. In order to test this, a failed connection to the origin is |
| 13467 | // mocked. This way the request relies on the alternate Job. |
| 13468 | StaticSocketDataProvider data_refused; |
| 13469 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 13470 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13471 | |
| 13472 | // Set up alternative service for origin. |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 13473 | session_deps_.parse_alternative_services = true; |
| 13474 | session_deps_.enable_alternative_service_with_different_host = true; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13475 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13476 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 13477 | session->http_server_properties(); |
| 13478 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13479 | AlternateProtocolFromNextProto(GetProtocol()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13480 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13481 | http_server_properties->SetAlternativeService(origin, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 13482 | expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13483 | |
| 13484 | scoped_ptr<HttpTransaction> trans( |
| 13485 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13486 | HttpRequestInfo request; |
| 13487 | request.method = "GET"; |
| 13488 | request.url = GURL("https://origin.example.org:443"); |
| 13489 | request.load_flags = 0; |
| 13490 | TestCompletionCallback callback; |
| 13491 | |
| 13492 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
| 13493 | // negotiated, the alternate Job should fail with ERR_NPN_NEGOTIATION_FAILED. |
| 13494 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13495 | EXPECT_EQ(ERR_NPN_NEGOTIATION_FAILED, callback.GetResult(rv)); |
| 13496 | } |
| 13497 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13498 | // A request to a server with an alternative service fires two Jobs: one to the |
| 13499 | // origin, and an alternate one to the alternative server. If the former |
| 13500 | // succeeds, the request should succeed, even if the latter fails because |
| 13501 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
| 13502 | TEST_P(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
| 13503 | HostPortPair origin("origin.example.org", 443); |
| 13504 | HostPortPair alternative("alternative.example.org", 443); |
| 13505 | |
| 13506 | // Negotiate HTTP/1.1 with alternative. |
| 13507 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
| 13508 | alternative_ssl.SetNextProto(kProtoHTTP11); |
| 13509 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 13510 | |
| 13511 | // No data should be read from the alternative, because HTTP/1.1 is |
| 13512 | // negotiated. |
| 13513 | StaticSocketDataProvider data; |
| 13514 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13515 | |
| 13516 | // Negotiate HTTP/1.1 with origin. |
| 13517 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
| 13518 | origin_ssl.SetNextProto(kProtoHTTP11); |
| 13519 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 13520 | |
| 13521 | MockWrite http_writes[] = { |
| 13522 | MockWrite( |
| 13523 | "GET / HTTP/1.1\r\n" |
| 13524 | "Host: origin.example.org\r\n" |
| 13525 | "Connection: keep-alive\r\n\r\n"), |
| 13526 | MockWrite( |
| 13527 | "GET /second HTTP/1.1\r\n" |
| 13528 | "Host: origin.example.org\r\n" |
| 13529 | "Connection: keep-alive\r\n\r\n"), |
| 13530 | }; |
| 13531 | |
| 13532 | MockRead http_reads[] = { |
| 13533 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13534 | MockRead("Content-Type: text/html\r\n"), |
| 13535 | MockRead("Content-Length: 6\r\n\r\n"), |
| 13536 | MockRead("foobar"), |
| 13537 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13538 | MockRead("Content-Type: text/html\r\n"), |
| 13539 | MockRead("Content-Length: 7\r\n\r\n"), |
| 13540 | MockRead("another"), |
| 13541 | }; |
| 13542 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13543 | http_writes, arraysize(http_writes)); |
| 13544 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13545 | |
| 13546 | // Set up alternative service for origin. |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 13547 | session_deps_.parse_alternative_services = true; |
| 13548 | session_deps_.enable_alternative_service_with_different_host = true; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13549 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13550 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 13551 | session->http_server_properties(); |
| 13552 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13553 | AlternateProtocolFromNextProto(GetProtocol()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13554 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13555 | http_server_properties->SetAlternativeService(origin, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 13556 | expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13557 | |
| 13558 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 13559 | HttpRequestInfo request1; |
| 13560 | request1.method = "GET"; |
| 13561 | request1.url = GURL("https://origin.example.org:443"); |
| 13562 | request1.load_flags = 0; |
| 13563 | TestCompletionCallback callback1; |
| 13564 | |
| 13565 | int rv = trans1.Start(&request1, callback1.callback(), BoundNetLog()); |
| 13566 | rv = callback1.GetResult(rv); |
| 13567 | EXPECT_EQ(OK, rv); |
| 13568 | |
| 13569 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
| 13570 | ASSERT_TRUE(response1 != nullptr); |
| 13571 | ASSERT_TRUE(response1->headers.get() != nullptr); |
| 13572 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 13573 | |
| 13574 | std::string response_data1; |
| 13575 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data1)); |
| 13576 | EXPECT_EQ("foobar", response_data1); |
| 13577 | |
| 13578 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 13579 | // for alternative service. |
| 13580 | EXPECT_TRUE( |
| 13581 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 13582 | |
| 13583 | // Since |alternative_service| is broken, a second transaction to origin |
| 13584 | // should not start an alternate Job. It should pool to existing connection |
| 13585 | // to origin. |
| 13586 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 13587 | HttpRequestInfo request2; |
| 13588 | request2.method = "GET"; |
| 13589 | request2.url = GURL("https://origin.example.org:443/second"); |
| 13590 | request2.load_flags = 0; |
| 13591 | TestCompletionCallback callback2; |
| 13592 | |
| 13593 | rv = trans2.Start(&request2, callback2.callback(), BoundNetLog()); |
| 13594 | rv = callback2.GetResult(rv); |
| 13595 | EXPECT_EQ(OK, rv); |
| 13596 | |
| 13597 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
| 13598 | ASSERT_TRUE(response2 != nullptr); |
| 13599 | ASSERT_TRUE(response2->headers.get() != nullptr); |
| 13600 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 13601 | |
| 13602 | std::string response_data2; |
| 13603 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data2)); |
| 13604 | EXPECT_EQ("another", response_data2); |
| 13605 | } |
| 13606 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13607 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 13608 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 13609 | // used. |
| 13610 | TEST_P(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
| 13611 | HostPortPair origin("origin.example.org", 443); |
| 13612 | HostPortPair alternative("alternative.example.org", 443); |
| 13613 | std::string origin_url = "https://origin.example.org:443"; |
| 13614 | std::string alternative_url = "https://alternative.example.org:443"; |
| 13615 | |
| 13616 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 13617 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13618 | ssl.SetNextProto(kProtoHTTP11); |
| 13619 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13620 | |
| 13621 | // HTTP/1.1 data for |request1| and |request2|. |
| 13622 | MockWrite http_writes[] = { |
| 13623 | MockWrite( |
| 13624 | "GET / HTTP/1.1\r\n" |
| 13625 | "Host: alternative.example.org\r\n" |
| 13626 | "Connection: keep-alive\r\n\r\n"), |
| 13627 | MockWrite( |
| 13628 | "GET / HTTP/1.1\r\n" |
| 13629 | "Host: alternative.example.org\r\n" |
| 13630 | "Connection: keep-alive\r\n\r\n"), |
| 13631 | }; |
| 13632 | |
| 13633 | MockRead http_reads[] = { |
| 13634 | MockRead( |
| 13635 | "HTTP/1.1 200 OK\r\n" |
| 13636 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13637 | "Content-Length: 40\r\n\r\n" |
| 13638 | "first HTTP/1.1 response from alternative"), |
| 13639 | MockRead( |
| 13640 | "HTTP/1.1 200 OK\r\n" |
| 13641 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13642 | "Content-Length: 41\r\n\r\n" |
| 13643 | "second HTTP/1.1 response from alternative"), |
| 13644 | }; |
| 13645 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13646 | http_writes, arraysize(http_writes)); |
| 13647 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13648 | |
| 13649 | // This test documents that an alternate Job should not pool to an already |
| 13650 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
| 13651 | // to the origin is mocked. This way |request2| relies on the alternate Job. |
| 13652 | StaticSocketDataProvider data_refused; |
| 13653 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 13654 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13655 | |
| 13656 | // Set up alternative service for origin. |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 13657 | session_deps_.parse_alternative_services = true; |
| 13658 | session_deps_.enable_alternative_service_with_different_host = false; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13659 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13660 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 13661 | session->http_server_properties(); |
| 13662 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13663 | AlternateProtocolFromNextProto(GetProtocol()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13664 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13665 | http_server_properties->SetAlternativeService(origin, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 13666 | expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13667 | |
| 13668 | // First transaction to alternative to open an HTTP/1.1 socket. |
| 13669 | scoped_ptr<HttpTransaction> trans1( |
| 13670 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13671 | HttpRequestInfo request1; |
| 13672 | request1.method = "GET"; |
| 13673 | request1.url = GURL(alternative_url); |
| 13674 | request1.load_flags = 0; |
| 13675 | TestCompletionCallback callback1; |
| 13676 | |
| 13677 | int rv = trans1->Start(&request1, callback1.callback(), BoundNetLog()); |
| 13678 | EXPECT_EQ(OK, callback1.GetResult(rv)); |
| 13679 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 13680 | ASSERT_TRUE(response1); |
| 13681 | ASSERT_TRUE(response1->headers.get()); |
| 13682 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 13683 | EXPECT_TRUE(response1->was_npn_negotiated); |
| 13684 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 13685 | std::string response_data1; |
| 13686 | ASSERT_EQ(OK, ReadTransaction(trans1.get(), &response_data1)); |
| 13687 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 13688 | |
| 13689 | // Request for origin.example.org, which has an alternative service. This |
| 13690 | // will start two Jobs: the alternative looks for connections to pool to, |
| 13691 | // finds one which is HTTP/1.1, and should ignore it, and should not try to |
| 13692 | // open other connections to alternative server. The Job to origin fails, so |
| 13693 | // this request fails. |
| 13694 | scoped_ptr<HttpTransaction> trans2( |
| 13695 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13696 | HttpRequestInfo request2; |
| 13697 | request2.method = "GET"; |
| 13698 | request2.url = GURL(origin_url); |
| 13699 | request2.load_flags = 0; |
| 13700 | TestCompletionCallback callback2; |
| 13701 | |
| 13702 | rv = trans2->Start(&request2, callback2.callback(), BoundNetLog()); |
| 13703 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback2.GetResult(rv)); |
| 13704 | |
| 13705 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 13706 | // socket is still open and in the pool. |
| 13707 | scoped_ptr<HttpTransaction> trans3( |
| 13708 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13709 | HttpRequestInfo request3; |
| 13710 | request3.method = "GET"; |
| 13711 | request3.url = GURL(alternative_url); |
| 13712 | request3.load_flags = 0; |
| 13713 | TestCompletionCallback callback3; |
| 13714 | |
| 13715 | rv = trans3->Start(&request3, callback3.callback(), BoundNetLog()); |
| 13716 | EXPECT_EQ(OK, callback3.GetResult(rv)); |
| 13717 | const HttpResponseInfo* response3 = trans3->GetResponseInfo(); |
| 13718 | ASSERT_TRUE(response3); |
| 13719 | ASSERT_TRUE(response3->headers.get()); |
| 13720 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
| 13721 | EXPECT_TRUE(response3->was_npn_negotiated); |
| 13722 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 13723 | std::string response_data3; |
| 13724 | ASSERT_EQ(OK, ReadTransaction(trans3.get(), &response_data3)); |
| 13725 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 13726 | } |
| 13727 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13728 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13729 | const std::string https_url = "https://www.example.org:8080/"; |
| 13730 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13731 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13732 | // Separate SPDY util instance for naked and wrapped requests. |
| 13733 | SpdyTestUtil spdy_util_wrapped(GetProtocol(), GetDependenciesFromPriority()); |
| 13734 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13735 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13736 | const HostPortPair host_port_pair("www.example.org", 8080); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 13737 | scoped_ptr<SpdySerializedFrame> connect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13738 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 13739 | scoped_ptr<SpdySerializedFrame> req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13740 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 13741 | scoped_ptr<SpdySerializedFrame> wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13742 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 13743 | |
| 13744 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13745 | SpdyHeaderBlock req2_block; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 13746 | spdy_util_.MaybeAddVersionHeader(&req2_block); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13747 | req2_block[spdy_util_.GetMethodKey()] = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13748 | req2_block[spdy_util_.GetHostKey()] = "www.example.org:8080"; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13749 | req2_block[spdy_util_.GetSchemeKey()] = "http"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 13750 | req2_block[spdy_util_.GetPathKey()] = "/"; |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 13751 | scoped_ptr<SpdySerializedFrame> req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13752 | spdy_util_.ConstructSpdySyn(3, req2_block, MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13753 | |
| 13754 | MockWrite writes1[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13755 | CreateMockWrite(*connect, 0), CreateMockWrite(*wrapped_req1, 2), |
| 13756 | CreateMockWrite(*req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13757 | }; |
| 13758 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 13759 | scoped_ptr<SpdySerializedFrame> conn_resp( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13760 | spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 13761 | scoped_ptr<SpdySerializedFrame> resp1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13762 | spdy_util_wrapped.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 13763 | scoped_ptr<SpdySerializedFrame> body1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13764 | spdy_util_wrapped.ConstructSpdyBodyFrame(1, true)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 13765 | scoped_ptr<SpdySerializedFrame> wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13766 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 13767 | scoped_ptr<SpdySerializedFrame> wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13768 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 13769 | scoped_ptr<SpdySerializedFrame> resp2( |
| 13770 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 13771 | scoped_ptr<SpdySerializedFrame> body2( |
| 13772 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13773 | MockRead reads1[] = { |
| 13774 | CreateMockRead(*conn_resp, 1), |
| 13775 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 13776 | CreateMockRead(*wrapped_resp1, 4), |
| 13777 | CreateMockRead(*wrapped_body1, 5), |
| 13778 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
| 13779 | CreateMockRead(*resp2, 8), |
| 13780 | CreateMockRead(*body2, 9), |
| 13781 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 13782 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13783 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13784 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 13785 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13786 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13787 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13788 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13789 | session_deps_.proxy_service = |
| 13790 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13791 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13792 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13793 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13794 | ssl1.SetNextProto(GetProtocol()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13795 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13796 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13797 | ssl2.SetNextProto(GetProtocol()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13798 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13799 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13800 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13801 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13802 | |
| 13803 | // Start the first transaction to set up the SpdySession |
| 13804 | HttpRequestInfo request1; |
| 13805 | request1.method = "GET"; |
| 13806 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13807 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13808 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13809 | TestCompletionCallback callback1; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13810 | int rv = trans1.Start(&request1, callback1.callback(), BoundNetLog()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13811 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13812 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 13813 | data1.RunUntilPaused(); |
| 13814 | base::RunLoop().RunUntilIdle(); |
| 13815 | data1.Resume(); |
| 13816 | EXPECT_EQ(OK, callback1.GetResult(rv)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13817 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 13818 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 13819 | LoadTimingInfo load_timing_info1; |
| 13820 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 13821 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 13822 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 13823 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13824 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13825 | HttpRequestInfo request2; |
| 13826 | request2.method = "GET"; |
| 13827 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13828 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13829 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13830 | TestCompletionCallback callback2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13831 | rv = trans2.Start(&request2, callback2.callback(), BoundNetLog()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13832 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13833 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 13834 | data1.RunUntilPaused(); |
| 13835 | base::RunLoop().RunUntilIdle(); |
| 13836 | data1.Resume(); |
| 13837 | EXPECT_EQ(OK, callback2.GetResult(rv)); |
| 13838 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13839 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 13840 | |
| 13841 | LoadTimingInfo load_timing_info2; |
| 13842 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 13843 | // The established SPDY sessions is considered reused by the HTTP request. |
| 13844 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 13845 | // HTTP requests over a SPDY session should have a different connection |
| 13846 | // socket_log_id than requests over a tunnel. |
| 13847 | 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] | 13848 | } |
| 13849 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13850 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 13851 | // that we do not pool other origins that resolve to the same IP when |
| 13852 | // the certificate does not match the new origin. |
| 13853 | // http://crbug.com/134690 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13854 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13855 | const std::string url1 = "http://www.example.org/"; |
| 13856 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13857 | const std::string ip_addr = "1.2.3.4"; |
| 13858 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13859 | // Second SpdyTestUtil instance for the second socket. |
| 13860 | SpdyTestUtil spdy_util_secure(GetProtocol(), GetDependenciesFromPriority()); |
| 13861 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13862 | // SPDY GET for HTTP URL (through SPDY proxy) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13863 | scoped_ptr<SpdyHeaderBlock> headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13864 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 13865 | scoped_ptr<SpdySerializedFrame> req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13866 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13867 | |
| 13868 | MockWrite writes1[] = { |
| 13869 | CreateMockWrite(*req1, 0), |
| 13870 | }; |
| 13871 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 13872 | scoped_ptr<SpdySerializedFrame> resp1( |
| 13873 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13874 | scoped_ptr<SpdySerializedFrame> body1( |
| 13875 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13876 | MockRead reads1[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13877 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(*resp1, 2), |
| 13878 | CreateMockRead(*body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13879 | }; |
| 13880 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13881 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 13882 | arraysize(writes1)); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 13883 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 13884 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13885 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 13886 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13887 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13888 | |
| 13889 | // SPDY GET for HTTPS URL (direct) |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 13890 | scoped_ptr<SpdySerializedFrame> req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13891 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13892 | |
| 13893 | MockWrite writes2[] = { |
| 13894 | CreateMockWrite(*req2, 0), |
| 13895 | }; |
| 13896 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 13897 | scoped_ptr<SpdySerializedFrame> resp2( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13898 | spdy_util_secure.ConstructSpdyGetSynReply(NULL, 0, 1)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 13899 | scoped_ptr<SpdySerializedFrame> body2( |
| 13900 | spdy_util_secure.ConstructSpdyBodyFrame(1, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13901 | MockRead reads2[] = {CreateMockRead(*resp2, 1), CreateMockRead(*body2, 2), |
| 13902 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13903 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13904 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 13905 | arraysize(writes2)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13906 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13907 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13908 | |
| 13909 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 13910 | // all others direct. |
| 13911 | ProxyConfig proxy_config; |
| 13912 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13913 | session_deps_.proxy_service.reset(new ProxyService( |
csharrison | b7e3a08 | 2015-09-22 19:13:04 | [diff] [blame] | 13914 | make_scoped_ptr(new ProxyConfigServiceFixed(proxy_config)), nullptr, |
| 13915 | NULL)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13916 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13917 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13918 | ssl1.SetNextProto(GetProtocol()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13919 | // Load a valid cert. Note, that this does not need to |
| 13920 | // be valid for proxy because the MockSSLClientSocket does |
| 13921 | // not actually verify it. But SpdySession will use this |
| 13922 | // to see if it is valid for the new origin |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13923 | ssl1.cert = ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 13924 | ASSERT_TRUE(ssl1.cert.get()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13925 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 13926 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13927 | |
| 13928 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13929 | ssl2.SetNextProto(GetProtocol()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13930 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13931 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13932 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13933 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13934 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13935 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13936 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13937 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13938 | |
| 13939 | // Start the first transaction to set up the SpdySession |
| 13940 | HttpRequestInfo request1; |
| 13941 | request1.method = "GET"; |
| 13942 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13943 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13944 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13945 | TestCompletionCallback callback1; |
| 13946 | ASSERT_EQ(ERR_IO_PENDING, |
| 13947 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13948 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 13949 | data1.RunUntilPaused(); |
| 13950 | base::RunLoop().RunUntilIdle(); |
| 13951 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13952 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13953 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 13954 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 13955 | |
| 13956 | // Now, start the HTTP request |
| 13957 | HttpRequestInfo request2; |
| 13958 | request2.method = "GET"; |
| 13959 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13960 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13961 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13962 | TestCompletionCallback callback2; |
| 13963 | EXPECT_EQ(ERR_IO_PENDING, |
| 13964 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 13965 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13966 | |
| 13967 | ASSERT_TRUE(callback2.have_result()); |
| 13968 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 13969 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 13970 | } |
| 13971 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13972 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 13973 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 13974 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 13975 | // SpdySession) do work. http://crbug.com/224701 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13976 | TEST_P(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13977 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13978 | |
| 13979 | MockRead reads1[] = { |
| 13980 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 13981 | }; |
| 13982 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13983 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13984 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 13985 | scoped_ptr<SpdySerializedFrame> req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13986 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13987 | MockWrite writes2[] = { |
| 13988 | CreateMockWrite(*req2, 0), |
| 13989 | }; |
| 13990 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 13991 | scoped_ptr<SpdySerializedFrame> resp2( |
| 13992 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13993 | scoped_ptr<SpdySerializedFrame> body2( |
| 13994 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13995 | MockRead reads2[] = { |
| 13996 | CreateMockRead(*resp2, 1), |
| 13997 | CreateMockRead(*body2, 2), |
| 13998 | MockRead(ASYNC, OK, 3) // EOF |
| 13999 | }; |
| 14000 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14001 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14002 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14003 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14004 | SSLSocketDataProvider ssl1(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14005 | ssl1.SetNextProto(GetProtocol()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14006 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14007 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14008 | |
| 14009 | SSLSocketDataProvider ssl2(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14010 | ssl2.SetNextProto(GetProtocol()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14011 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14012 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14013 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14014 | scoped_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14015 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14016 | |
| 14017 | // Start the first transaction to set up the SpdySession and verify that |
| 14018 | // connection was closed. |
| 14019 | HttpRequestInfo request1; |
| 14020 | request1.method = "GET"; |
| 14021 | request1.url = GURL(https_url); |
| 14022 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14023 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14024 | TestCompletionCallback callback1; |
| 14025 | EXPECT_EQ(ERR_IO_PENDING, |
| 14026 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14027 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback1.WaitForResult()); |
| 14028 | |
| 14029 | // Now, start the second request and make sure it succeeds. |
| 14030 | HttpRequestInfo request2; |
| 14031 | request2.method = "GET"; |
| 14032 | request2.url = GURL(https_url); |
| 14033 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14034 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14035 | TestCompletionCallback callback2; |
| 14036 | EXPECT_EQ(ERR_IO_PENDING, |
| 14037 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14038 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14039 | ASSERT_EQ(OK, callback2.WaitForResult()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14040 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14041 | } |
| 14042 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 14043 | TEST_P(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14044 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 14045 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14046 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 14047 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14048 | |
| 14049 | // Use two different hosts with different IPs so they don't get pooled. |
| 14050 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 14051 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14052 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14053 | |
| 14054 | SSLSocketDataProvider ssl1(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14055 | ssl1.SetNextProto(GetProtocol()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14056 | SSLSocketDataProvider ssl2(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14057 | ssl2.SetNextProto(GetProtocol()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14058 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14059 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14060 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 14061 | scoped_ptr<SpdySerializedFrame> host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14062 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14063 | MockWrite spdy1_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14064 | CreateMockWrite(*host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14065 | }; |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 14066 | scoped_ptr<SpdySerializedFrame> host1_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 14067 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 14068 | scoped_ptr<SpdySerializedFrame> host1_resp_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 14069 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14070 | MockRead spdy1_reads[] = { |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14071 | CreateMockRead(*host1_resp, 1), CreateMockRead(*host1_resp_body, 2), |
| 14072 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14073 | }; |
| 14074 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14075 | // Use a separate test instance for the separate SpdySession that will be |
| 14076 | // created. |
| 14077 | SpdyTestUtil spdy_util_2(GetProtocol(), GetDependenciesFromPriority()); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14078 | scoped_ptr<SequencedSocketData> spdy1_data( |
| 14079 | new SequencedSocketData(spdy1_reads, arraysize(spdy1_reads), spdy1_writes, |
| 14080 | arraysize(spdy1_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14081 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 14082 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 14083 | scoped_ptr<SpdySerializedFrame> host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14084 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14085 | MockWrite spdy2_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14086 | CreateMockWrite(*host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14087 | }; |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 14088 | scoped_ptr<SpdySerializedFrame> host2_resp( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14089 | spdy_util_2.ConstructSpdyGetSynReply(NULL, 0, 1)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 14090 | scoped_ptr<SpdySerializedFrame> host2_resp_body( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14091 | spdy_util_2.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14092 | MockRead spdy2_reads[] = { |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14093 | CreateMockRead(*host2_resp, 1), CreateMockRead(*host2_resp_body, 2), |
| 14094 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14095 | }; |
| 14096 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14097 | scoped_ptr<SequencedSocketData> spdy2_data( |
| 14098 | new SequencedSocketData(spdy2_reads, arraysize(spdy2_reads), spdy2_writes, |
| 14099 | arraysize(spdy2_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14100 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 14101 | |
| 14102 | MockWrite http_write[] = { |
| 14103 | MockWrite("GET / HTTP/1.1\r\n" |
| 14104 | "Host: www.a.com\r\n" |
| 14105 | "Connection: keep-alive\r\n\r\n"), |
| 14106 | }; |
| 14107 | |
| 14108 | MockRead http_read[] = { |
| 14109 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14110 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14111 | MockRead("Content-Length: 6\r\n\r\n"), |
| 14112 | MockRead("hello!"), |
| 14113 | }; |
| 14114 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 14115 | http_write, arraysize(http_write)); |
| 14116 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14117 | |
| 14118 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14119 | SpdySessionKey spdy_session_key_a( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14120 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14121 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14122 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14123 | |
| 14124 | TestCompletionCallback callback; |
| 14125 | HttpRequestInfo request1; |
| 14126 | request1.method = "GET"; |
| 14127 | request1.url = GURL("https://www.a.com/"); |
| 14128 | request1.load_flags = 0; |
| 14129 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14130 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14131 | |
| 14132 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 14133 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14134 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 14135 | |
| 14136 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14137 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14138 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14139 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14140 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14141 | EXPECT_TRUE(response->was_npn_negotiated); |
| 14142 | |
| 14143 | std::string response_data; |
| 14144 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 14145 | EXPECT_EQ("hello!", response_data); |
| 14146 | trans.reset(); |
| 14147 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14148 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14149 | |
| 14150 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14151 | SpdySessionKey spdy_session_key_b( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14152 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14153 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14154 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14155 | HttpRequestInfo request2; |
| 14156 | request2.method = "GET"; |
| 14157 | request2.url = GURL("https://www.b.com/"); |
| 14158 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14159 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14160 | |
| 14161 | rv = trans->Start(&request2, callback.callback(), BoundNetLog()); |
| 14162 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14163 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 14164 | |
| 14165 | response = trans->GetResponseInfo(); |
| 14166 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14167 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14168 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14169 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14170 | EXPECT_TRUE(response->was_npn_negotiated); |
| 14171 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 14172 | EXPECT_EQ("hello!", response_data); |
| 14173 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14174 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14175 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14176 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14177 | |
| 14178 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14179 | SpdySessionKey spdy_session_key_a1( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14180 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14181 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14182 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14183 | HttpRequestInfo request3; |
| 14184 | request3.method = "GET"; |
| 14185 | request3.url = GURL("http://www.a.com/"); |
| 14186 | request3.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14187 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14188 | |
| 14189 | rv = trans->Start(&request3, callback.callback(), BoundNetLog()); |
| 14190 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14191 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 14192 | |
| 14193 | response = trans->GetResponseInfo(); |
| 14194 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14195 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14196 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14197 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 14198 | EXPECT_FALSE(response->was_npn_negotiated); |
| 14199 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 14200 | EXPECT_EQ("hello!", response_data); |
| 14201 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14202 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14203 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14204 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14205 | } |
| 14206 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14207 | TEST_P(HttpNetworkTransactionTest, HttpSyncConnectError) { |
| 14208 | HttpRequestInfo request; |
| 14209 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14210 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14211 | request.load_flags = 0; |
| 14212 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14213 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14214 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14215 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14216 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14217 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14218 | StaticSocketDataProvider data; |
| 14219 | data.set_connect_data(mock_connect); |
| 14220 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14221 | |
| 14222 | TestCompletionCallback callback; |
| 14223 | |
| 14224 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14225 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14226 | |
| 14227 | rv = callback.WaitForResult(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14228 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14229 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14230 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 14231 | HttpRequestHeaders request_headers; |
| 14232 | trans->GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14233 | |
| 14234 | ConnectionAttempts attempts; |
| 14235 | trans->GetConnectionAttempts(&attempts); |
| 14236 | ASSERT_EQ(1u, attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14237 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, attempts[0].result); |
| 14238 | |
| 14239 | IPEndPoint endpoint; |
| 14240 | EXPECT_FALSE(trans->GetRemoteEndpoint(&endpoint)); |
| 14241 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14242 | } |
| 14243 | |
| 14244 | TEST_P(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
| 14245 | HttpRequestInfo request; |
| 14246 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14247 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14248 | request.load_flags = 0; |
| 14249 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14250 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14251 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14252 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14253 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14254 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14255 | StaticSocketDataProvider data; |
| 14256 | data.set_connect_data(mock_connect); |
| 14257 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14258 | |
| 14259 | TestCompletionCallback callback; |
| 14260 | |
| 14261 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14262 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14263 | |
| 14264 | rv = callback.WaitForResult(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14265 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14266 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14267 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 14268 | HttpRequestHeaders request_headers; |
| 14269 | trans->GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14270 | |
| 14271 | ConnectionAttempts attempts; |
| 14272 | trans->GetConnectionAttempts(&attempts); |
| 14273 | ASSERT_EQ(1u, attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14274 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, attempts[0].result); |
| 14275 | |
| 14276 | IPEndPoint endpoint; |
| 14277 | EXPECT_FALSE(trans->GetRemoteEndpoint(&endpoint)); |
| 14278 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14279 | } |
| 14280 | |
| 14281 | TEST_P(HttpNetworkTransactionTest, HttpSyncWriteError) { |
| 14282 | HttpRequestInfo request; |
| 14283 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14284 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14285 | request.load_flags = 0; |
| 14286 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14287 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14288 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14289 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14290 | |
| 14291 | MockWrite data_writes[] = { |
| 14292 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14293 | }; |
| 14294 | MockRead data_reads[] = { |
| 14295 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 14296 | }; |
| 14297 | |
| 14298 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14299 | data_writes, arraysize(data_writes)); |
| 14300 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14301 | |
| 14302 | TestCompletionCallback callback; |
| 14303 | |
| 14304 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14305 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14306 | |
| 14307 | rv = callback.WaitForResult(); |
| 14308 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 14309 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14310 | HttpRequestHeaders request_headers; |
| 14311 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 14312 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14313 | } |
| 14314 | |
| 14315 | TEST_P(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
| 14316 | HttpRequestInfo request; |
| 14317 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14318 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14319 | request.load_flags = 0; |
| 14320 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14321 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14322 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14323 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14324 | |
| 14325 | MockWrite data_writes[] = { |
| 14326 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 14327 | }; |
| 14328 | MockRead data_reads[] = { |
| 14329 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 14330 | }; |
| 14331 | |
| 14332 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14333 | data_writes, arraysize(data_writes)); |
| 14334 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14335 | |
| 14336 | TestCompletionCallback callback; |
| 14337 | |
| 14338 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14339 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14340 | |
| 14341 | rv = callback.WaitForResult(); |
| 14342 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 14343 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14344 | HttpRequestHeaders request_headers; |
| 14345 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 14346 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14347 | } |
| 14348 | |
| 14349 | TEST_P(HttpNetworkTransactionTest, HttpSyncReadError) { |
| 14350 | HttpRequestInfo request; |
| 14351 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14352 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14353 | request.load_flags = 0; |
| 14354 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14355 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14356 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14357 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14358 | |
| 14359 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14360 | MockWrite( |
| 14361 | "GET / HTTP/1.1\r\n" |
| 14362 | "Host: www.example.org\r\n" |
| 14363 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14364 | }; |
| 14365 | MockRead data_reads[] = { |
| 14366 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14367 | }; |
| 14368 | |
| 14369 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14370 | data_writes, arraysize(data_writes)); |
| 14371 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14372 | |
| 14373 | TestCompletionCallback callback; |
| 14374 | |
| 14375 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14376 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14377 | |
| 14378 | rv = callback.WaitForResult(); |
| 14379 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 14380 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14381 | HttpRequestHeaders request_headers; |
| 14382 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 14383 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14384 | } |
| 14385 | |
| 14386 | TEST_P(HttpNetworkTransactionTest, HttpAsyncReadError) { |
| 14387 | HttpRequestInfo request; |
| 14388 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14389 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14390 | request.load_flags = 0; |
| 14391 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14392 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14393 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14394 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14395 | |
| 14396 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14397 | MockWrite( |
| 14398 | "GET / HTTP/1.1\r\n" |
| 14399 | "Host: www.example.org\r\n" |
| 14400 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14401 | }; |
| 14402 | MockRead data_reads[] = { |
| 14403 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 14404 | }; |
| 14405 | |
| 14406 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14407 | data_writes, arraysize(data_writes)); |
| 14408 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14409 | |
| 14410 | TestCompletionCallback callback; |
| 14411 | |
| 14412 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14413 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14414 | |
| 14415 | rv = callback.WaitForResult(); |
| 14416 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 14417 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14418 | HttpRequestHeaders request_headers; |
| 14419 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 14420 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14421 | } |
| 14422 | |
| 14423 | TEST_P(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
| 14424 | HttpRequestInfo request; |
| 14425 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14426 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14427 | request.load_flags = 0; |
| 14428 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 14429 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14430 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14431 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14432 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14433 | |
| 14434 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14435 | MockWrite( |
| 14436 | "GET / HTTP/1.1\r\n" |
| 14437 | "Host: www.example.org\r\n" |
| 14438 | "Connection: keep-alive\r\n" |
| 14439 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14440 | }; |
| 14441 | MockRead data_reads[] = { |
| 14442 | MockRead("HTTP/1.1 200 OK\r\n" |
| 14443 | "Content-Length: 5\r\n\r\n" |
| 14444 | "hello"), |
| 14445 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 14446 | }; |
| 14447 | |
| 14448 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14449 | data_writes, arraysize(data_writes)); |
| 14450 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14451 | |
| 14452 | TestCompletionCallback callback; |
| 14453 | |
| 14454 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14455 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14456 | |
| 14457 | rv = callback.WaitForResult(); |
| 14458 | EXPECT_EQ(OK, rv); |
| 14459 | |
| 14460 | HttpRequestHeaders request_headers; |
| 14461 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 14462 | std::string foo; |
| 14463 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 14464 | EXPECT_EQ("bar", foo); |
| 14465 | } |
| 14466 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14467 | namespace { |
| 14468 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 14469 | // Fake HttpStream that simply records calls to SetPriority(). |
| 14470 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14471 | public base::SupportsWeakPtr<FakeStream> { |
| 14472 | public: |
| 14473 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14474 | ~FakeStream() override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14475 | |
| 14476 | RequestPriority priority() const { return priority_; } |
| 14477 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14478 | int InitializeStream(const HttpRequestInfo* request_info, |
| 14479 | RequestPriority priority, |
| 14480 | const BoundNetLog& net_log, |
| 14481 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14482 | return ERR_IO_PENDING; |
| 14483 | } |
| 14484 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14485 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 14486 | HttpResponseInfo* response, |
| 14487 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14488 | ADD_FAILURE(); |
| 14489 | return ERR_UNEXPECTED; |
| 14490 | } |
| 14491 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14492 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14493 | ADD_FAILURE(); |
| 14494 | return ERR_UNEXPECTED; |
| 14495 | } |
| 14496 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14497 | int ReadResponseBody(IOBuffer* buf, |
| 14498 | int buf_len, |
| 14499 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14500 | ADD_FAILURE(); |
| 14501 | return ERR_UNEXPECTED; |
| 14502 | } |
| 14503 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14504 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14505 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14506 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14507 | ADD_FAILURE(); |
| 14508 | return false; |
| 14509 | } |
| 14510 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14511 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14512 | ADD_FAILURE(); |
| 14513 | return false; |
| 14514 | } |
| 14515 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14516 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14517 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 14518 | bool CanReuseConnection() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14519 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 14520 | int64_t GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 14521 | ADD_FAILURE(); |
| 14522 | return 0; |
| 14523 | } |
| 14524 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 14525 | int64_t GetTotalSentBytes() const override { |
| 14526 | ADD_FAILURE(); |
| 14527 | return 0; |
| 14528 | } |
| 14529 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14530 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14531 | ADD_FAILURE(); |
| 14532 | return false; |
| 14533 | } |
| 14534 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14535 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 14536 | |
| 14537 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14538 | ADD_FAILURE(); |
| 14539 | } |
| 14540 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14541 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 14542 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 14543 | Error GetSignedEKMForTokenBinding(crypto::ECPrivateKey* key, |
| 14544 | std::vector<uint8_t>* out) override { |
| 14545 | ADD_FAILURE(); |
| 14546 | return ERR_NOT_IMPLEMENTED; |
| 14547 | } |
| 14548 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14549 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14550 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 14551 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 14552 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14553 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14554 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 14555 | UploadProgress GetUploadProgress() const override { return UploadProgress(); } |
| 14556 | |
| 14557 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 14558 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14559 | private: |
| 14560 | RequestPriority priority_; |
| 14561 | |
| 14562 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 14563 | }; |
| 14564 | |
| 14565 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 14566 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14567 | class FakeStreamRequest : public HttpStreamRequest, |
| 14568 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 14569 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14570 | FakeStreamRequest(RequestPriority priority, |
| 14571 | HttpStreamRequest::Delegate* delegate) |
| 14572 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14573 | delegate_(delegate), |
| 14574 | websocket_stream_create_helper_(NULL) {} |
| 14575 | |
| 14576 | FakeStreamRequest(RequestPriority priority, |
| 14577 | HttpStreamRequest::Delegate* delegate, |
| 14578 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 14579 | : priority_(priority), |
| 14580 | delegate_(delegate), |
| 14581 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14582 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14583 | ~FakeStreamRequest() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14584 | |
| 14585 | RequestPriority priority() const { return priority_; } |
| 14586 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14587 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 14588 | websocket_stream_create_helper() const { |
| 14589 | return websocket_stream_create_helper_; |
| 14590 | } |
| 14591 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14592 | // Create a new FakeStream and pass it to the request's |
| 14593 | // delegate. Returns a weak pointer to the FakeStream. |
| 14594 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
| 14595 | FakeStream* fake_stream = new FakeStream(priority_); |
| 14596 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 14597 | // immediately delete |fake_stream|. |
| 14598 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
| 14599 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), fake_stream); |
| 14600 | return weak_stream; |
| 14601 | } |
| 14602 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14603 | int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14604 | ADD_FAILURE(); |
| 14605 | return ERR_UNEXPECTED; |
| 14606 | } |
| 14607 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14608 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14609 | ADD_FAILURE(); |
| 14610 | return LoadState(); |
| 14611 | } |
| 14612 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14613 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14614 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14615 | bool was_npn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14616 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14617 | NextProto protocol_negotiated() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14618 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14619 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14620 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14621 | const ConnectionAttempts& connection_attempts() const override { |
| 14622 | static ConnectionAttempts no_attempts; |
| 14623 | return no_attempts; |
| 14624 | } |
| 14625 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14626 | private: |
| 14627 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14628 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14629 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14630 | |
| 14631 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 14632 | }; |
| 14633 | |
| 14634 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 14635 | class FakeStreamFactory : public HttpStreamFactory { |
| 14636 | public: |
| 14637 | FakeStreamFactory() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14638 | ~FakeStreamFactory() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14639 | |
| 14640 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 14641 | // RequestStream() (which may be NULL if it was destroyed already). |
| 14642 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 14643 | return last_stream_request_; |
| 14644 | } |
| 14645 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14646 | HttpStreamRequest* RequestStream(const HttpRequestInfo& info, |
| 14647 | RequestPriority priority, |
| 14648 | const SSLConfig& server_ssl_config, |
| 14649 | const SSLConfig& proxy_ssl_config, |
| 14650 | HttpStreamRequest::Delegate* delegate, |
| 14651 | const BoundNetLog& net_log) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14652 | FakeStreamRequest* fake_request = new FakeStreamRequest(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14653 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 14654 | return fake_request; |
| 14655 | } |
| 14656 | |
xunjieli | 5749218c | 2016-03-22 16:43:06 | [diff] [blame] | 14657 | HttpStreamRequest* RequestBidirectionalStreamImpl( |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 14658 | const HttpRequestInfo& info, |
| 14659 | RequestPriority priority, |
| 14660 | const SSLConfig& server_ssl_config, |
| 14661 | const SSLConfig& proxy_ssl_config, |
| 14662 | HttpStreamRequest::Delegate* delegate, |
| 14663 | const BoundNetLog& net_log) override { |
| 14664 | NOTREACHED(); |
| 14665 | return nullptr; |
| 14666 | } |
| 14667 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14668 | HttpStreamRequest* RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14669 | const HttpRequestInfo& info, |
| 14670 | RequestPriority priority, |
| 14671 | const SSLConfig& server_ssl_config, |
| 14672 | const SSLConfig& proxy_ssl_config, |
| 14673 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 14674 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 14675 | const BoundNetLog& net_log) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14676 | FakeStreamRequest* fake_request = |
| 14677 | new FakeStreamRequest(priority, delegate, create_helper); |
| 14678 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 14679 | return fake_request; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14680 | } |
| 14681 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14682 | void PreconnectStreams(int num_streams, |
| 14683 | const HttpRequestInfo& info, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14684 | const SSLConfig& server_ssl_config, |
| 14685 | const SSLConfig& proxy_ssl_config) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14686 | ADD_FAILURE(); |
| 14687 | } |
| 14688 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14689 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14690 | ADD_FAILURE(); |
| 14691 | return NULL; |
| 14692 | } |
| 14693 | |
| 14694 | private: |
| 14695 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 14696 | |
| 14697 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 14698 | }; |
| 14699 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14700 | // TODO(ricea): Maybe unify this with the one in |
| 14701 | // url_request_http_job_unittest.cc ? |
| 14702 | class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { |
| 14703 | public: |
| 14704 | FakeWebSocketBasicHandshakeStream(scoped_ptr<ClientSocketHandle> connection, |
| 14705 | bool using_proxy) |
| 14706 | : state_(connection.release(), using_proxy) {} |
| 14707 | |
| 14708 | // Fake implementation of HttpStreamBase methods. |
| 14709 | // This ends up being quite "real" because this object has to really send data |
| 14710 | // on the mock socket. It might be easier to use the real implementation, but |
| 14711 | // the fact that the WebSocket code is not compiled on iOS makes that |
| 14712 | // difficult. |
| 14713 | int InitializeStream(const HttpRequestInfo* request_info, |
| 14714 | RequestPriority priority, |
| 14715 | const BoundNetLog& net_log, |
| 14716 | const CompletionCallback& callback) override { |
| 14717 | state_.Initialize(request_info, priority, net_log, callback); |
| 14718 | return OK; |
| 14719 | } |
| 14720 | |
| 14721 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 14722 | HttpResponseInfo* response, |
| 14723 | const CompletionCallback& callback) override { |
| 14724 | return parser()->SendRequest(state_.GenerateRequestLine(), request_headers, |
| 14725 | response, callback); |
| 14726 | } |
| 14727 | |
| 14728 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
| 14729 | return parser()->ReadResponseHeaders(callback); |
| 14730 | } |
| 14731 | |
| 14732 | int ReadResponseBody(IOBuffer* buf, |
| 14733 | int buf_len, |
| 14734 | const CompletionCallback& callback) override { |
| 14735 | NOTREACHED(); |
| 14736 | return ERR_IO_PENDING; |
| 14737 | } |
| 14738 | |
| 14739 | void Close(bool not_reusable) override { |
| 14740 | if (parser()) |
| 14741 | parser()->Close(true); |
| 14742 | } |
| 14743 | |
| 14744 | bool IsResponseBodyComplete() const override { |
| 14745 | NOTREACHED(); |
| 14746 | return false; |
| 14747 | } |
| 14748 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14749 | bool IsConnectionReused() const override { |
| 14750 | NOTREACHED(); |
| 14751 | return false; |
| 14752 | } |
| 14753 | void SetConnectionReused() override { NOTREACHED(); } |
| 14754 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 14755 | bool CanReuseConnection() const override { return false; } |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14756 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 14757 | int64_t GetTotalReceivedBytes() const override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14758 | NOTREACHED(); |
| 14759 | return 0; |
| 14760 | } |
| 14761 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 14762 | int64_t GetTotalSentBytes() const override { |
| 14763 | NOTREACHED(); |
| 14764 | return 0; |
| 14765 | } |
| 14766 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14767 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
| 14768 | NOTREACHED(); |
| 14769 | return false; |
| 14770 | } |
| 14771 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 14772 | void GetSSLInfo(SSLInfo* ssl_info) override {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14773 | |
| 14774 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
| 14775 | NOTREACHED(); |
| 14776 | } |
| 14777 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14778 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 14779 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 14780 | Error GetSignedEKMForTokenBinding(crypto::ECPrivateKey* key, |
| 14781 | std::vector<uint8_t>* out) override { |
| 14782 | ADD_FAILURE(); |
| 14783 | return ERR_NOT_IMPLEMENTED; |
| 14784 | } |
| 14785 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14786 | void Drain(HttpNetworkSession* session) override { NOTREACHED(); } |
| 14787 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 14788 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 14789 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14790 | void SetPriority(RequestPriority priority) override { NOTREACHED(); } |
| 14791 | |
| 14792 | UploadProgress GetUploadProgress() const override { |
| 14793 | NOTREACHED(); |
| 14794 | return UploadProgress(); |
| 14795 | } |
| 14796 | |
| 14797 | HttpStream* RenewStreamForAuth() override { |
| 14798 | NOTREACHED(); |
| 14799 | return nullptr; |
| 14800 | } |
| 14801 | |
| 14802 | // Fake implementation of WebSocketHandshakeStreamBase method(s) |
| 14803 | scoped_ptr<WebSocketStream> Upgrade() override { |
| 14804 | NOTREACHED(); |
| 14805 | return scoped_ptr<WebSocketStream>(); |
| 14806 | } |
| 14807 | |
| 14808 | private: |
| 14809 | HttpStreamParser* parser() const { return state_.parser(); } |
| 14810 | HttpBasicState state_; |
| 14811 | |
| 14812 | DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream); |
| 14813 | }; |
| 14814 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14815 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 14816 | // worth doing. |
| 14817 | class FakeWebSocketStreamCreateHelper : |
| 14818 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 14819 | public: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14820 | WebSocketHandshakeStreamBase* CreateBasicStream( |
[email protected] | 7e841a5 | 2013-11-22 09:04:21 | [diff] [blame] | 14821 | scoped_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 14822 | bool using_proxy) override { |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 14823 | return new FakeWebSocketBasicHandshakeStream(std::move(connection), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14824 | using_proxy); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14825 | } |
| 14826 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14827 | WebSocketHandshakeStreamBase* CreateSpdyStream( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14828 | const base::WeakPtr<SpdySession>& session, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 14829 | bool use_relative_url) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14830 | NOTREACHED(); |
| 14831 | return NULL; |
| 14832 | }; |
| 14833 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14834 | ~FakeWebSocketStreamCreateHelper() override {} |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14835 | |
| 14836 | virtual scoped_ptr<WebSocketStream> Upgrade() { |
| 14837 | NOTREACHED(); |
| 14838 | return scoped_ptr<WebSocketStream>(); |
| 14839 | } |
| 14840 | }; |
| 14841 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14842 | } // namespace |
| 14843 | |
| 14844 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 14845 | // stream request on start. |
| 14846 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14847 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14848 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14849 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14850 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14851 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14852 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14853 | |
| 14854 | ASSERT_TRUE(fake_factory->last_stream_request() == NULL); |
| 14855 | |
| 14856 | HttpRequestInfo request; |
| 14857 | TestCompletionCallback callback; |
| 14858 | EXPECT_EQ(ERR_IO_PENDING, |
| 14859 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14860 | |
| 14861 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14862 | fake_factory->last_stream_request(); |
| 14863 | ASSERT_TRUE(fake_request != NULL); |
| 14864 | EXPECT_EQ(LOW, fake_request->priority()); |
| 14865 | } |
| 14866 | |
| 14867 | // Make sure that HttpNetworkTransaction passes on its priority |
| 14868 | // updates to its stream request. |
| 14869 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14870 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14871 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14872 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14873 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14874 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14875 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14876 | |
| 14877 | HttpRequestInfo request; |
| 14878 | TestCompletionCallback callback; |
| 14879 | EXPECT_EQ(ERR_IO_PENDING, |
| 14880 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14881 | |
| 14882 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14883 | fake_factory->last_stream_request(); |
| 14884 | ASSERT_TRUE(fake_request != NULL); |
| 14885 | EXPECT_EQ(LOW, fake_request->priority()); |
| 14886 | |
| 14887 | trans.SetPriority(LOWEST); |
| 14888 | ASSERT_TRUE(fake_request != NULL); |
| 14889 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 14890 | } |
| 14891 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14892 | // Make sure that HttpNetworkTransaction passes on its priority |
| 14893 | // updates to its stream. |
| 14894 | TEST_P(HttpNetworkTransactionTest, SetStreamPriority) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14895 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14896 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14897 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14898 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14899 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14900 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14901 | |
| 14902 | HttpRequestInfo request; |
| 14903 | TestCompletionCallback callback; |
| 14904 | EXPECT_EQ(ERR_IO_PENDING, |
| 14905 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14906 | |
| 14907 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14908 | fake_factory->last_stream_request(); |
| 14909 | ASSERT_TRUE(fake_request != NULL); |
| 14910 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
| 14911 | ASSERT_TRUE(fake_stream != NULL); |
| 14912 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 14913 | |
| 14914 | trans.SetPriority(LOWEST); |
| 14915 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 14916 | } |
| 14917 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14918 | TEST_P(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
| 14919 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 14920 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 14921 | // that the different schemes work. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14922 | std::string test_cases[] = {"ws://www.example.org/", |
| 14923 | "wss://www.example.org/"}; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14924 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14925 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14926 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14927 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 14928 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
[email protected] | 0191b51c | 2013-11-18 10:55:23 | [diff] [blame] | 14929 | peer.SetHttpStreamFactoryForWebSocket( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14930 | scoped_ptr<HttpStreamFactory>(fake_factory)); |
| 14931 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14932 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14933 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 14934 | &websocket_stream_create_helper); |
| 14935 | |
| 14936 | HttpRequestInfo request; |
| 14937 | TestCompletionCallback callback; |
| 14938 | request.method = "GET"; |
| 14939 | request.url = GURL(test_cases[i]); |
| 14940 | |
| 14941 | EXPECT_EQ(ERR_IO_PENDING, |
| 14942 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14943 | |
| 14944 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14945 | fake_factory->last_stream_request(); |
| 14946 | ASSERT_TRUE(fake_request != NULL); |
| 14947 | EXPECT_EQ(&websocket_stream_create_helper, |
| 14948 | fake_request->websocket_stream_create_helper()); |
| 14949 | } |
| 14950 | } |
| 14951 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14952 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 14953 | // if the transport socket pool is stalled on the global socket limit. |
| 14954 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
| 14955 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 14956 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14957 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 14958 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14959 | |
| 14960 | // Set up SSL request. |
| 14961 | |
| 14962 | HttpRequestInfo ssl_request; |
| 14963 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14964 | ssl_request.url = GURL("https://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14965 | |
| 14966 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14967 | MockWrite( |
| 14968 | "GET / HTTP/1.1\r\n" |
| 14969 | "Host: www.example.org\r\n" |
| 14970 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14971 | }; |
| 14972 | MockRead ssl_reads[] = { |
| 14973 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14974 | MockRead("Content-Length: 11\r\n\r\n"), |
| 14975 | MockRead("hello world"), |
| 14976 | MockRead(SYNCHRONOUS, OK), |
| 14977 | }; |
| 14978 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 14979 | ssl_writes, arraysize(ssl_writes)); |
| 14980 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 14981 | |
| 14982 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14983 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14984 | |
| 14985 | // Set up HTTP request. |
| 14986 | |
| 14987 | HttpRequestInfo http_request; |
| 14988 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14989 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14990 | |
| 14991 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14992 | MockWrite( |
| 14993 | "GET / HTTP/1.1\r\n" |
| 14994 | "Host: www.example.org\r\n" |
| 14995 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14996 | }; |
| 14997 | MockRead http_reads[] = { |
| 14998 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14999 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15000 | MockRead("falafel"), |
| 15001 | MockRead(SYNCHRONOUS, OK), |
| 15002 | }; |
| 15003 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15004 | http_writes, arraysize(http_writes)); |
| 15005 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15006 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15007 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15008 | |
| 15009 | // Start the SSL request. |
| 15010 | TestCompletionCallback ssl_callback; |
| 15011 | scoped_ptr<HttpTransaction> ssl_trans( |
| 15012 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15013 | ASSERT_EQ(ERR_IO_PENDING, |
| 15014 | ssl_trans->Start(&ssl_request, ssl_callback.callback(), |
| 15015 | BoundNetLog())); |
| 15016 | |
| 15017 | // Start the HTTP request. Pool should stall. |
| 15018 | TestCompletionCallback http_callback; |
| 15019 | scoped_ptr<HttpTransaction> http_trans( |
| 15020 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15021 | ASSERT_EQ(ERR_IO_PENDING, |
| 15022 | http_trans->Start(&http_request, http_callback.callback(), |
| 15023 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15024 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15025 | |
| 15026 | // Wait for response from SSL request. |
| 15027 | ASSERT_EQ(OK, ssl_callback.WaitForResult()); |
| 15028 | std::string response_data; |
| 15029 | ASSERT_EQ(OK, ReadTransaction(ssl_trans.get(), &response_data)); |
| 15030 | EXPECT_EQ("hello world", response_data); |
| 15031 | |
| 15032 | // The SSL socket should automatically be closed, so the HTTP request can |
| 15033 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15034 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 15035 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15036 | |
| 15037 | // The HTTP request can now complete. |
| 15038 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 15039 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 15040 | EXPECT_EQ("falafel", response_data); |
| 15041 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15042 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15043 | } |
| 15044 | |
| 15045 | // Tests that when a SSL connection is established but there's no corresponding |
| 15046 | // request that needs it, the new socket is closed if the transport socket pool |
| 15047 | // is stalled on the global socket limit. |
| 15048 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
| 15049 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15050 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15051 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15052 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15053 | |
| 15054 | // Set up an ssl request. |
| 15055 | |
| 15056 | HttpRequestInfo ssl_request; |
| 15057 | ssl_request.method = "GET"; |
| 15058 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 15059 | |
| 15060 | // No data will be sent on the SSL socket. |
| 15061 | StaticSocketDataProvider ssl_data; |
| 15062 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 15063 | |
| 15064 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15065 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15066 | |
| 15067 | // Set up HTTP request. |
| 15068 | |
| 15069 | HttpRequestInfo http_request; |
| 15070 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15071 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15072 | |
| 15073 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15074 | MockWrite( |
| 15075 | "GET / HTTP/1.1\r\n" |
| 15076 | "Host: www.example.org\r\n" |
| 15077 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15078 | }; |
| 15079 | MockRead http_reads[] = { |
| 15080 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15081 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15082 | MockRead("falafel"), |
| 15083 | MockRead(SYNCHRONOUS, OK), |
| 15084 | }; |
| 15085 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15086 | http_writes, arraysize(http_writes)); |
| 15087 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15088 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15089 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15090 | |
| 15091 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 15092 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15093 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
| 15094 | SSLConfig ssl_config; |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15095 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
mmenke | d1205bd | 2015-07-15 22:26:35 | [diff] [blame] | 15096 | http_stream_factory->PreconnectStreams(1, ssl_request, ssl_config, |
| 15097 | ssl_config); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15098 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15099 | |
| 15100 | // Start the HTTP request. Pool should stall. |
| 15101 | TestCompletionCallback http_callback; |
| 15102 | scoped_ptr<HttpTransaction> http_trans( |
| 15103 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15104 | ASSERT_EQ(ERR_IO_PENDING, |
| 15105 | http_trans->Start(&http_request, http_callback.callback(), |
| 15106 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15107 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15108 | |
| 15109 | // The SSL connection will automatically be closed once the connection is |
| 15110 | // established, to let the HTTP request start. |
| 15111 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 15112 | std::string response_data; |
| 15113 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 15114 | EXPECT_EQ("falafel", response_data); |
| 15115 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15116 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15117 | } |
| 15118 | |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15119 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15120 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15121 | element_readers.push_back( |
| 15122 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15123 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15124 | |
| 15125 | HttpRequestInfo request; |
| 15126 | request.method = "POST"; |
| 15127 | request.url = GURL("http://www.foo.com/"); |
| 15128 | request.upload_data_stream = &upload_data_stream; |
| 15129 | request.load_flags = 0; |
| 15130 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15131 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15132 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15133 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15134 | // Send headers successfully, but get an error while sending the body. |
| 15135 | MockWrite data_writes[] = { |
| 15136 | MockWrite("POST / HTTP/1.1\r\n" |
| 15137 | "Host: www.foo.com\r\n" |
| 15138 | "Connection: keep-alive\r\n" |
| 15139 | "Content-Length: 3\r\n\r\n"), |
| 15140 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15141 | }; |
| 15142 | |
| 15143 | MockRead data_reads[] = { |
| 15144 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15145 | MockRead("hello world"), |
| 15146 | MockRead(SYNCHRONOUS, OK), |
| 15147 | }; |
| 15148 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15149 | arraysize(data_writes)); |
| 15150 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15151 | |
| 15152 | TestCompletionCallback callback; |
| 15153 | |
| 15154 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15155 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15156 | |
| 15157 | rv = callback.WaitForResult(); |
| 15158 | EXPECT_EQ(OK, rv); |
| 15159 | |
| 15160 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15161 | ASSERT_TRUE(response != NULL); |
| 15162 | |
| 15163 | EXPECT_TRUE(response->headers.get() != NULL); |
| 15164 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15165 | |
| 15166 | std::string response_data; |
| 15167 | rv = ReadTransaction(trans.get(), &response_data); |
| 15168 | EXPECT_EQ(OK, rv); |
| 15169 | EXPECT_EQ("hello world", response_data); |
| 15170 | } |
| 15171 | |
| 15172 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 15173 | // response from a server that rejected a POST with a CONNECTION_RESET. |
| 15174 | TEST_P(HttpNetworkTransactionTest, |
| 15175 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15176 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15177 | MockWrite data_writes[] = { |
| 15178 | MockWrite("GET / HTTP/1.1\r\n" |
| 15179 | "Host: www.foo.com\r\n" |
| 15180 | "Connection: keep-alive\r\n\r\n"), |
| 15181 | MockWrite("POST / HTTP/1.1\r\n" |
| 15182 | "Host: www.foo.com\r\n" |
| 15183 | "Connection: keep-alive\r\n" |
| 15184 | "Content-Length: 3\r\n\r\n"), |
| 15185 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15186 | }; |
| 15187 | |
| 15188 | MockRead data_reads[] = { |
| 15189 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 15190 | "Content-Length: 14\r\n\r\n"), |
| 15191 | MockRead("first response"), |
| 15192 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 15193 | "Content-Length: 15\r\n\r\n"), |
| 15194 | MockRead("second response"), |
| 15195 | MockRead(SYNCHRONOUS, OK), |
| 15196 | }; |
| 15197 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15198 | arraysize(data_writes)); |
| 15199 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15200 | |
| 15201 | TestCompletionCallback callback; |
| 15202 | HttpRequestInfo request1; |
| 15203 | request1.method = "GET"; |
| 15204 | request1.url = GURL("http://www.foo.com/"); |
| 15205 | request1.load_flags = 0; |
| 15206 | |
| 15207 | scoped_ptr<HttpTransaction> trans1( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15208 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15209 | int rv = trans1->Start(&request1, callback.callback(), BoundNetLog()); |
| 15210 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15211 | |
| 15212 | rv = callback.WaitForResult(); |
| 15213 | EXPECT_EQ(OK, rv); |
| 15214 | |
| 15215 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 15216 | ASSERT_TRUE(response1 != NULL); |
| 15217 | |
| 15218 | EXPECT_TRUE(response1->headers.get() != NULL); |
| 15219 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 15220 | |
| 15221 | std::string response_data1; |
| 15222 | rv = ReadTransaction(trans1.get(), &response_data1); |
| 15223 | EXPECT_EQ(OK, rv); |
| 15224 | EXPECT_EQ("first response", response_data1); |
| 15225 | // Delete the transaction to release the socket back into the socket pool. |
| 15226 | trans1.reset(); |
| 15227 | |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15228 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15229 | element_readers.push_back( |
| 15230 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15231 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15232 | |
| 15233 | HttpRequestInfo request2; |
| 15234 | request2.method = "POST"; |
| 15235 | request2.url = GURL("http://www.foo.com/"); |
| 15236 | request2.upload_data_stream = &upload_data_stream; |
| 15237 | request2.load_flags = 0; |
| 15238 | |
| 15239 | scoped_ptr<HttpTransaction> trans2( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15240 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15241 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 15242 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15243 | |
| 15244 | rv = callback.WaitForResult(); |
| 15245 | EXPECT_EQ(OK, rv); |
| 15246 | |
| 15247 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 15248 | ASSERT_TRUE(response2 != NULL); |
| 15249 | |
| 15250 | EXPECT_TRUE(response2->headers.get() != NULL); |
| 15251 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 15252 | |
| 15253 | std::string response_data2; |
| 15254 | rv = ReadTransaction(trans2.get(), &response_data2); |
| 15255 | EXPECT_EQ(OK, rv); |
| 15256 | EXPECT_EQ("second response", response_data2); |
| 15257 | } |
| 15258 | |
| 15259 | TEST_P(HttpNetworkTransactionTest, |
| 15260 | PostReadsErrorResponseAfterResetPartialBodySent) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15261 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15262 | element_readers.push_back( |
| 15263 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15264 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15265 | |
| 15266 | HttpRequestInfo request; |
| 15267 | request.method = "POST"; |
| 15268 | request.url = GURL("http://www.foo.com/"); |
| 15269 | request.upload_data_stream = &upload_data_stream; |
| 15270 | request.load_flags = 0; |
| 15271 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15272 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15273 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15274 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15275 | // Send headers successfully, but get an error while sending the body. |
| 15276 | MockWrite data_writes[] = { |
| 15277 | MockWrite("POST / HTTP/1.1\r\n" |
| 15278 | "Host: www.foo.com\r\n" |
| 15279 | "Connection: keep-alive\r\n" |
| 15280 | "Content-Length: 3\r\n\r\n" |
| 15281 | "fo"), |
| 15282 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15283 | }; |
| 15284 | |
| 15285 | MockRead data_reads[] = { |
| 15286 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15287 | MockRead("hello world"), |
| 15288 | MockRead(SYNCHRONOUS, OK), |
| 15289 | }; |
| 15290 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15291 | arraysize(data_writes)); |
| 15292 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15293 | |
| 15294 | TestCompletionCallback callback; |
| 15295 | |
| 15296 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15297 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15298 | |
| 15299 | rv = callback.WaitForResult(); |
| 15300 | EXPECT_EQ(OK, rv); |
| 15301 | |
| 15302 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15303 | ASSERT_TRUE(response != NULL); |
| 15304 | |
| 15305 | EXPECT_TRUE(response->headers.get() != NULL); |
| 15306 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15307 | |
| 15308 | std::string response_data; |
| 15309 | rv = ReadTransaction(trans.get(), &response_data); |
| 15310 | EXPECT_EQ(OK, rv); |
| 15311 | EXPECT_EQ("hello world", response_data); |
| 15312 | } |
| 15313 | |
| 15314 | // This tests the more common case than the previous test, where headers and |
| 15315 | // body are not merged into a single request. |
| 15316 | TEST_P(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 15317 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15318 | |
| 15319 | HttpRequestInfo request; |
| 15320 | request.method = "POST"; |
| 15321 | request.url = GURL("http://www.foo.com/"); |
| 15322 | request.upload_data_stream = &upload_data_stream; |
| 15323 | request.load_flags = 0; |
| 15324 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15325 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15326 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15327 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15328 | // Send headers successfully, but get an error while sending the body. |
| 15329 | MockWrite data_writes[] = { |
| 15330 | MockWrite("POST / HTTP/1.1\r\n" |
| 15331 | "Host: www.foo.com\r\n" |
| 15332 | "Connection: keep-alive\r\n" |
| 15333 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 15334 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15335 | }; |
| 15336 | |
| 15337 | MockRead data_reads[] = { |
| 15338 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15339 | MockRead("hello world"), |
| 15340 | MockRead(SYNCHRONOUS, OK), |
| 15341 | }; |
| 15342 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15343 | arraysize(data_writes)); |
| 15344 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15345 | |
| 15346 | TestCompletionCallback callback; |
| 15347 | |
| 15348 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15349 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15350 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 15351 | // they can't be merged with the body in a single send. Not currently |
| 15352 | // necessary since a chunked body is never merged with headers, but this makes |
| 15353 | // the test more future proof. |
| 15354 | base::RunLoop().RunUntilIdle(); |
| 15355 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 15356 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15357 | |
| 15358 | rv = callback.WaitForResult(); |
| 15359 | EXPECT_EQ(OK, rv); |
| 15360 | |
| 15361 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15362 | ASSERT_TRUE(response != NULL); |
| 15363 | |
| 15364 | EXPECT_TRUE(response->headers.get() != NULL); |
| 15365 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15366 | |
| 15367 | std::string response_data; |
| 15368 | rv = ReadTransaction(trans.get(), &response_data); |
| 15369 | EXPECT_EQ(OK, rv); |
| 15370 | EXPECT_EQ("hello world", response_data); |
| 15371 | } |
| 15372 | |
| 15373 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15374 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15375 | element_readers.push_back( |
| 15376 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15377 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15378 | |
| 15379 | HttpRequestInfo request; |
| 15380 | request.method = "POST"; |
| 15381 | request.url = GURL("http://www.foo.com/"); |
| 15382 | request.upload_data_stream = &upload_data_stream; |
| 15383 | request.load_flags = 0; |
| 15384 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15385 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15386 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15387 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15388 | |
| 15389 | MockWrite data_writes[] = { |
| 15390 | MockWrite("POST / HTTP/1.1\r\n" |
| 15391 | "Host: www.foo.com\r\n" |
| 15392 | "Connection: keep-alive\r\n" |
| 15393 | "Content-Length: 3\r\n\r\n"), |
| 15394 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15395 | }; |
| 15396 | |
| 15397 | MockRead data_reads[] = { |
| 15398 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 15399 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15400 | MockRead("hello world"), |
| 15401 | MockRead(SYNCHRONOUS, OK), |
| 15402 | }; |
| 15403 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15404 | arraysize(data_writes)); |
| 15405 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15406 | |
| 15407 | TestCompletionCallback callback; |
| 15408 | |
| 15409 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15410 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15411 | |
| 15412 | rv = callback.WaitForResult(); |
| 15413 | EXPECT_EQ(OK, rv); |
| 15414 | |
| 15415 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15416 | ASSERT_TRUE(response != NULL); |
| 15417 | |
| 15418 | EXPECT_TRUE(response->headers.get() != NULL); |
| 15419 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15420 | |
| 15421 | std::string response_data; |
| 15422 | rv = ReadTransaction(trans.get(), &response_data); |
| 15423 | EXPECT_EQ(OK, rv); |
| 15424 | EXPECT_EQ("hello world", response_data); |
| 15425 | } |
| 15426 | |
| 15427 | TEST_P(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15428 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15429 | element_readers.push_back( |
| 15430 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15431 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15432 | |
| 15433 | HttpRequestInfo request; |
| 15434 | request.method = "POST"; |
| 15435 | request.url = GURL("http://www.foo.com/"); |
| 15436 | request.upload_data_stream = &upload_data_stream; |
| 15437 | request.load_flags = 0; |
| 15438 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15439 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15440 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15441 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15442 | // Send headers successfully, but get an error while sending the body. |
| 15443 | MockWrite data_writes[] = { |
| 15444 | MockWrite("POST / HTTP/1.1\r\n" |
| 15445 | "Host: www.foo.com\r\n" |
| 15446 | "Connection: keep-alive\r\n" |
| 15447 | "Content-Length: 3\r\n\r\n"), |
| 15448 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15449 | }; |
| 15450 | |
| 15451 | MockRead data_reads[] = { |
| 15452 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 15453 | MockRead("hello world"), |
| 15454 | MockRead(SYNCHRONOUS, OK), |
| 15455 | }; |
| 15456 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15457 | arraysize(data_writes)); |
| 15458 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15459 | |
| 15460 | TestCompletionCallback callback; |
| 15461 | |
| 15462 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15463 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15464 | |
| 15465 | rv = callback.WaitForResult(); |
| 15466 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15467 | } |
| 15468 | |
| 15469 | TEST_P(HttpNetworkTransactionTest, |
| 15470 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15471 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15472 | element_readers.push_back( |
| 15473 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15474 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15475 | |
| 15476 | HttpRequestInfo request; |
| 15477 | request.method = "POST"; |
| 15478 | request.url = GURL("http://www.foo.com/"); |
| 15479 | request.upload_data_stream = &upload_data_stream; |
| 15480 | request.load_flags = 0; |
| 15481 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15482 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15483 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15484 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15485 | // Send headers successfully, but get an error while sending the body. |
| 15486 | MockWrite data_writes[] = { |
| 15487 | MockWrite("POST / HTTP/1.1\r\n" |
| 15488 | "Host: www.foo.com\r\n" |
| 15489 | "Connection: keep-alive\r\n" |
| 15490 | "Content-Length: 3\r\n\r\n"), |
| 15491 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15492 | }; |
| 15493 | |
| 15494 | MockRead data_reads[] = { |
| 15495 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 15496 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 15497 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 15498 | MockRead("Content-Length: 0\r\n\r\n"), |
| 15499 | MockRead(SYNCHRONOUS, OK), |
| 15500 | }; |
| 15501 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15502 | arraysize(data_writes)); |
| 15503 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15504 | |
| 15505 | TestCompletionCallback callback; |
| 15506 | |
| 15507 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15508 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15509 | |
| 15510 | rv = callback.WaitForResult(); |
| 15511 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15512 | } |
| 15513 | |
| 15514 | TEST_P(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15515 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15516 | element_readers.push_back( |
| 15517 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15518 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15519 | |
| 15520 | HttpRequestInfo request; |
| 15521 | request.method = "POST"; |
| 15522 | request.url = GURL("http://www.foo.com/"); |
| 15523 | request.upload_data_stream = &upload_data_stream; |
| 15524 | request.load_flags = 0; |
| 15525 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15526 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15527 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15528 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15529 | // Send headers successfully, but get an error while sending the body. |
| 15530 | MockWrite data_writes[] = { |
| 15531 | MockWrite("POST / HTTP/1.1\r\n" |
| 15532 | "Host: www.foo.com\r\n" |
| 15533 | "Connection: keep-alive\r\n" |
| 15534 | "Content-Length: 3\r\n\r\n"), |
| 15535 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15536 | }; |
| 15537 | |
| 15538 | MockRead data_reads[] = { |
| 15539 | MockRead("HTTP 0.9 rocks!"), |
| 15540 | MockRead(SYNCHRONOUS, OK), |
| 15541 | }; |
| 15542 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15543 | arraysize(data_writes)); |
| 15544 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15545 | |
| 15546 | TestCompletionCallback callback; |
| 15547 | |
| 15548 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15549 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15550 | |
| 15551 | rv = callback.WaitForResult(); |
| 15552 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15553 | } |
| 15554 | |
| 15555 | TEST_P(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15556 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15557 | element_readers.push_back( |
| 15558 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15559 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15560 | |
| 15561 | HttpRequestInfo request; |
| 15562 | request.method = "POST"; |
| 15563 | request.url = GURL("http://www.foo.com/"); |
| 15564 | request.upload_data_stream = &upload_data_stream; |
| 15565 | request.load_flags = 0; |
| 15566 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15567 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15568 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15569 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15570 | // Send headers successfully, but get an error while sending the body. |
| 15571 | MockWrite data_writes[] = { |
| 15572 | MockWrite("POST / HTTP/1.1\r\n" |
| 15573 | "Host: www.foo.com\r\n" |
| 15574 | "Connection: keep-alive\r\n" |
| 15575 | "Content-Length: 3\r\n\r\n"), |
| 15576 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15577 | }; |
| 15578 | |
| 15579 | MockRead data_reads[] = { |
| 15580 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 15581 | MockRead(SYNCHRONOUS, OK), |
| 15582 | }; |
| 15583 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15584 | arraysize(data_writes)); |
| 15585 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15586 | |
| 15587 | TestCompletionCallback callback; |
| 15588 | |
| 15589 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15590 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15591 | |
| 15592 | rv = callback.WaitForResult(); |
| 15593 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15594 | } |
| 15595 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15596 | // Verify that proxy headers are not sent to the destination server when |
| 15597 | // establishing a tunnel for a secure WebSocket connection. |
| 15598 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
| 15599 | HttpRequestInfo request; |
| 15600 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15601 | request.url = GURL("wss://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15602 | AddWebSocketHeaders(&request.extra_headers); |
| 15603 | |
| 15604 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 15605 | session_deps_.proxy_service = |
| 15606 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15607 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15608 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15609 | |
| 15610 | // Since a proxy is configured, try to establish a tunnel. |
| 15611 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15612 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15613 | "Host: www.example.org:443\r\n" |
| 15614 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15615 | |
| 15616 | // After calling trans->RestartWithAuth(), this is the request we should |
| 15617 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15618 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15619 | "Host: www.example.org:443\r\n" |
| 15620 | "Proxy-Connection: keep-alive\r\n" |
| 15621 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15622 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15623 | MockWrite("GET / HTTP/1.1\r\n" |
| 15624 | "Host: www.example.org\r\n" |
| 15625 | "Connection: Upgrade\r\n" |
| 15626 | "Upgrade: websocket\r\n" |
| 15627 | "Origin: http://www.example.org\r\n" |
| 15628 | "Sec-WebSocket-Version: 13\r\n" |
| 15629 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15630 | }; |
| 15631 | |
| 15632 | // The proxy responds to the connect with a 407, using a persistent |
| 15633 | // connection. |
| 15634 | MockRead data_reads[] = { |
| 15635 | // No credentials. |
| 15636 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 15637 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 15638 | MockRead("Content-Length: 0\r\n"), |
| 15639 | MockRead("Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15640 | |
| 15641 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 15642 | |
| 15643 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 15644 | MockRead("Upgrade: websocket\r\n"), |
| 15645 | MockRead("Connection: Upgrade\r\n"), |
| 15646 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 15647 | }; |
| 15648 | |
| 15649 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15650 | arraysize(data_writes)); |
| 15651 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15652 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15653 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15654 | |
| 15655 | scoped_ptr<HttpTransaction> trans( |
| 15656 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15657 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 15658 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 15659 | &websocket_stream_create_helper); |
| 15660 | |
| 15661 | { |
| 15662 | TestCompletionCallback callback; |
| 15663 | |
| 15664 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15665 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15666 | |
| 15667 | rv = callback.WaitForResult(); |
| 15668 | EXPECT_EQ(OK, rv); |
| 15669 | } |
| 15670 | |
| 15671 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15672 | ASSERT_TRUE(response); |
| 15673 | ASSERT_TRUE(response->headers.get()); |
| 15674 | EXPECT_EQ(407, response->headers->response_code()); |
| 15675 | |
| 15676 | { |
| 15677 | TestCompletionCallback callback; |
| 15678 | |
| 15679 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 15680 | callback.callback()); |
| 15681 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15682 | |
| 15683 | rv = callback.WaitForResult(); |
| 15684 | EXPECT_EQ(OK, rv); |
| 15685 | } |
| 15686 | |
| 15687 | response = trans->GetResponseInfo(); |
| 15688 | ASSERT_TRUE(response); |
| 15689 | ASSERT_TRUE(response->headers.get()); |
| 15690 | |
| 15691 | EXPECT_EQ(101, response->headers->response_code()); |
| 15692 | |
| 15693 | trans.reset(); |
| 15694 | session->CloseAllConnections(); |
| 15695 | } |
| 15696 | |
| 15697 | // Verify that proxy headers are not sent to the destination server when |
| 15698 | // establishing a tunnel for an insecure WebSocket connection. |
| 15699 | // This requires the authentication info to be injected into the auth cache |
| 15700 | // due to crbug.com/395064 |
| 15701 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
| 15702 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
| 15703 | HttpRequestInfo request; |
| 15704 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15705 | request.url = GURL("ws://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15706 | AddWebSocketHeaders(&request.extra_headers); |
| 15707 | |
| 15708 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 15709 | session_deps_.proxy_service = |
| 15710 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15711 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15712 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15713 | |
| 15714 | MockWrite data_writes[] = { |
| 15715 | // Try to establish a tunnel for the WebSocket connection, with |
| 15716 | // credentials. Because WebSockets have a separate set of socket pools, |
| 15717 | // they cannot and will not use the same TCP/IP connection as the |
| 15718 | // preflight HTTP request. |
| 15719 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15720 | "CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 15721 | "Host: www.example.org:80\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15722 | "Proxy-Connection: keep-alive\r\n" |
| 15723 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 15724 | |
| 15725 | MockWrite( |
| 15726 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15727 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15728 | "Connection: Upgrade\r\n" |
| 15729 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15730 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15731 | "Sec-WebSocket-Version: 13\r\n" |
| 15732 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 15733 | }; |
| 15734 | |
| 15735 | MockRead data_reads[] = { |
| 15736 | // HTTP CONNECT with credentials. |
| 15737 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 15738 | |
| 15739 | // WebSocket connection established inside tunnel. |
| 15740 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 15741 | MockRead("Upgrade: websocket\r\n"), |
| 15742 | MockRead("Connection: Upgrade\r\n"), |
| 15743 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 15744 | }; |
| 15745 | |
| 15746 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15747 | arraysize(data_writes)); |
| 15748 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15749 | |
| 15750 | session->http_auth_cache()->Add( |
| 15751 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 15752 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 15753 | |
| 15754 | scoped_ptr<HttpTransaction> trans( |
| 15755 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15756 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 15757 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 15758 | &websocket_stream_create_helper); |
| 15759 | |
| 15760 | TestCompletionCallback callback; |
| 15761 | |
| 15762 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15763 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15764 | |
| 15765 | rv = callback.WaitForResult(); |
| 15766 | EXPECT_EQ(OK, rv); |
| 15767 | |
| 15768 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15769 | ASSERT_TRUE(response); |
| 15770 | ASSERT_TRUE(response->headers.get()); |
| 15771 | |
| 15772 | EXPECT_EQ(101, response->headers->response_code()); |
| 15773 | |
| 15774 | trans.reset(); |
| 15775 | session->CloseAllConnections(); |
| 15776 | } |
| 15777 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15778 | TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15779 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15780 | element_readers.push_back( |
| 15781 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15782 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15783 | |
| 15784 | HttpRequestInfo request; |
| 15785 | request.method = "POST"; |
| 15786 | request.url = GURL("http://www.foo.com/"); |
| 15787 | request.upload_data_stream = &upload_data_stream; |
| 15788 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15789 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15790 | scoped_ptr<HttpTransaction> trans( |
| 15791 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15792 | MockWrite data_writes[] = { |
| 15793 | MockWrite("POST / HTTP/1.1\r\n" |
| 15794 | "Host: www.foo.com\r\n" |
| 15795 | "Connection: keep-alive\r\n" |
| 15796 | "Content-Length: 3\r\n\r\n"), |
| 15797 | MockWrite("foo"), |
| 15798 | }; |
| 15799 | |
| 15800 | MockRead data_reads[] = { |
| 15801 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 15802 | MockRead(SYNCHRONOUS, OK), |
| 15803 | }; |
| 15804 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15805 | arraysize(data_writes)); |
| 15806 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15807 | |
| 15808 | TestCompletionCallback callback; |
| 15809 | |
| 15810 | EXPECT_EQ(ERR_IO_PENDING, |
| 15811 | trans->Start(&request, callback.callback(), BoundNetLog())); |
| 15812 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 15813 | |
| 15814 | std::string response_data; |
| 15815 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 15816 | |
| 15817 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 15818 | trans->GetTotalSentBytes()); |
| 15819 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 15820 | trans->GetTotalReceivedBytes()); |
| 15821 | } |
| 15822 | |
| 15823 | TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15824 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15825 | element_readers.push_back( |
| 15826 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15827 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15828 | |
| 15829 | HttpRequestInfo request; |
| 15830 | request.method = "POST"; |
| 15831 | request.url = GURL("http://www.foo.com/"); |
| 15832 | request.upload_data_stream = &upload_data_stream; |
| 15833 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15834 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15835 | scoped_ptr<HttpTransaction> trans( |
| 15836 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15837 | MockWrite data_writes[] = { |
| 15838 | MockWrite("POST / HTTP/1.1\r\n" |
| 15839 | "Host: www.foo.com\r\n" |
| 15840 | "Connection: keep-alive\r\n" |
| 15841 | "Content-Length: 3\r\n\r\n"), |
| 15842 | MockWrite("foo"), |
| 15843 | }; |
| 15844 | |
| 15845 | MockRead data_reads[] = { |
| 15846 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 15847 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 15848 | MockRead(SYNCHRONOUS, OK), |
| 15849 | }; |
| 15850 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15851 | arraysize(data_writes)); |
| 15852 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15853 | |
| 15854 | TestCompletionCallback callback; |
| 15855 | |
| 15856 | EXPECT_EQ(ERR_IO_PENDING, |
| 15857 | trans->Start(&request, callback.callback(), BoundNetLog())); |
| 15858 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 15859 | |
| 15860 | std::string response_data; |
| 15861 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 15862 | |
| 15863 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 15864 | trans->GetTotalSentBytes()); |
| 15865 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 15866 | trans->GetTotalReceivedBytes()); |
| 15867 | } |
| 15868 | |
| 15869 | TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15870 | ChunkedUploadDataStream upload_data_stream(0); |
| 15871 | |
| 15872 | HttpRequestInfo request; |
| 15873 | request.method = "POST"; |
| 15874 | request.url = GURL("http://www.foo.com/"); |
| 15875 | request.upload_data_stream = &upload_data_stream; |
| 15876 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15877 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15878 | scoped_ptr<HttpTransaction> trans( |
| 15879 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15880 | // Send headers successfully, but get an error while sending the body. |
| 15881 | MockWrite data_writes[] = { |
| 15882 | MockWrite("POST / HTTP/1.1\r\n" |
| 15883 | "Host: www.foo.com\r\n" |
| 15884 | "Connection: keep-alive\r\n" |
| 15885 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 15886 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 15887 | }; |
| 15888 | |
| 15889 | MockRead data_reads[] = { |
| 15890 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 15891 | MockRead(SYNCHRONOUS, OK), |
| 15892 | }; |
| 15893 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15894 | arraysize(data_writes)); |
| 15895 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15896 | |
| 15897 | TestCompletionCallback callback; |
| 15898 | |
| 15899 | EXPECT_EQ(ERR_IO_PENDING, |
| 15900 | trans->Start(&request, callback.callback(), BoundNetLog())); |
| 15901 | |
| 15902 | base::RunLoop().RunUntilIdle(); |
| 15903 | upload_data_stream.AppendData("f", 1, false); |
| 15904 | |
| 15905 | base::RunLoop().RunUntilIdle(); |
| 15906 | upload_data_stream.AppendData("oo", 2, true); |
| 15907 | |
| 15908 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 15909 | |
| 15910 | std::string response_data; |
| 15911 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 15912 | |
| 15913 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 15914 | trans->GetTotalSentBytes()); |
| 15915 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 15916 | trans->GetTotalReceivedBytes()); |
| 15917 | } |
| 15918 | |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 15919 | TEST_P(HttpNetworkTransactionTest, EnableNPN) { |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 15920 | session_deps_.enable_npn = true; |
| 15921 | |
| 15922 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15923 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 15924 | |
| 15925 | EXPECT_THAT(trans.server_ssl_config_.alpn_protos, |
| 15926 | testing::ElementsAre(kProtoHTTP2, kProtoSPDY31, kProtoHTTP11)); |
| 15927 | EXPECT_THAT(trans.server_ssl_config_.npn_protos, |
| 15928 | testing::ElementsAre(kProtoHTTP2, kProtoSPDY31, kProtoHTTP11)); |
| 15929 | } |
| 15930 | |
| 15931 | TEST_P(HttpNetworkTransactionTest, DisableNPN) { |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 15932 | session_deps_.enable_npn = false; |
| 15933 | |
| 15934 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15935 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 15936 | |
| 15937 | EXPECT_THAT(trans.server_ssl_config_.alpn_protos, |
| 15938 | testing::ElementsAre(kProtoHTTP2, kProtoSPDY31, kProtoHTTP11)); |
| 15939 | EXPECT_TRUE(trans.server_ssl_config_.npn_protos.empty()); |
| 15940 | } |
| 15941 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15942 | #if !defined(OS_IOS) |
| 15943 | TEST_P(HttpNetworkTransactionTest, TokenBindingSpdy) { |
| 15944 | const std::string https_url = "https://www.example.com"; |
| 15945 | HttpRequestInfo request; |
| 15946 | request.url = GURL(https_url); |
| 15947 | request.method = "GET"; |
| 15948 | |
| 15949 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15950 | ssl.token_binding_negotiated = true; |
| 15951 | ssl.token_binding_key_param = TB_PARAM_ECDSAP256; |
| 15952 | ssl.SetNextProto(GetProtocol()); |
| 15953 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15954 | |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 15955 | scoped_ptr<SpdySerializedFrame> resp( |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15956 | spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame^] | 15957 | scoped_ptr<SpdySerializedFrame> body( |
| 15958 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15959 | MockRead reads[] = {CreateMockRead(*resp), CreateMockRead(*body), |
| 15960 | MockRead(ASYNC, ERR_IO_PENDING)}; |
| 15961 | StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); |
| 15962 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15963 | session_deps_.channel_id_service.reset(new ChannelIDService( |
| 15964 | new DefaultChannelIDStore(nullptr), base::ThreadTaskRunnerHandle::Get())); |
| 15965 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15966 | |
| 15967 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 15968 | TestCompletionCallback callback; |
| 15969 | EXPECT_EQ(ERR_IO_PENDING, |
| 15970 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 15971 | base::MessageLoop::current()->RunUntilIdle(); |
| 15972 | |
| 15973 | EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| 15974 | HttpRequestHeaders headers; |
| 15975 | ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
| 15976 | EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 15977 | } |
| 15978 | #endif // !defined(OS_IOS) |
| 15979 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 15980 | } // namespace net |