[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. |
| 1440 | scoped_ptr<SpdyFrame> spdy_request(spdy_util_.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1441 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1442 | scoped_ptr<SpdyFrame> spdy_response( |
| 1443 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1444 | scoped_ptr<SpdyFrame> spdy_data( |
| 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 |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4218 | scoped_ptr<SpdyFrame> 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 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4222 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4223 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4224 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4225 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4226 | }; |
| 4227 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4228 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4229 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4230 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4231 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4232 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4233 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4234 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4235 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4236 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4237 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4238 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4239 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4240 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4241 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4242 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4243 | |
| 4244 | rv = callback1.WaitForResult(); |
| 4245 | EXPECT_EQ(OK, rv); |
| 4246 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4247 | LoadTimingInfo load_timing_info; |
| 4248 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4249 | TestLoadTimingNotReused(load_timing_info, |
| 4250 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4251 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4252 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4253 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4254 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4255 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4256 | |
| 4257 | std::string response_data; |
| 4258 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4259 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4260 | } |
| 4261 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4262 | // Verifies that a session which races and wins against the owning transaction |
| 4263 | // (completing prior to host resolution), doesn't fail the transaction. |
| 4264 | // Regression test for crbug.com/334413. |
| 4265 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
| 4266 | HttpRequestInfo request; |
| 4267 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4268 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4269 | request.load_flags = 0; |
| 4270 | |
| 4271 | // Configure SPDY proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4272 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4273 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4274 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4275 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4276 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4277 | // Fetch http://www.example.org/ through the SPDY proxy. |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4278 | scoped_ptr<SpdyFrame> req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4279 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, false)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4280 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4281 | |
| 4282 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4283 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 4284 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4285 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4286 | }; |
| 4287 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4288 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4289 | arraysize(spdy_writes)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4290 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 4291 | |
| 4292 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4293 | ssl.SetNextProto(GetProtocol()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4294 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4295 | |
| 4296 | TestCompletionCallback callback1; |
| 4297 | |
| 4298 | scoped_ptr<HttpTransaction> trans( |
| 4299 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 4300 | |
| 4301 | // Stall the hostname resolution begun by the transaction. |
| 4302 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 4303 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4304 | |
| 4305 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 4306 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4307 | |
| 4308 | // Race a session to the proxy, which completes first. |
| 4309 | session_deps_.host_resolver->set_ondemand_mode(false); |
| 4310 | SpdySessionKey key( |
| 4311 | HostPortPair("proxy", 70), ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 4312 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4313 | CreateSecureSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4314 | |
| 4315 | // Unstall the resolution begun by the transaction. |
| 4316 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4317 | session_deps_.host_resolver->ResolveAllPending(); |
| 4318 | |
| 4319 | EXPECT_FALSE(callback1.have_result()); |
| 4320 | rv = callback1.WaitForResult(); |
| 4321 | EXPECT_EQ(OK, rv); |
| 4322 | |
| 4323 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4324 | ASSERT_TRUE(response != NULL); |
| 4325 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4326 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4327 | |
| 4328 | std::string response_data; |
| 4329 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 4330 | EXPECT_EQ(kUploadData, response_data); |
| 4331 | } |
| 4332 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4333 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4334 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4335 | HttpRequestInfo request; |
| 4336 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4337 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4338 | request.load_flags = 0; |
| 4339 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4340 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4341 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4342 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4343 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4344 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4345 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4346 | // The first request will be a bare GET, the second request will be a |
| 4347 | // GET with a Proxy-Authorization header. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4348 | scoped_ptr<SpdyFrame> req_get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4349 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, false)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4350 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4351 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4352 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4353 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4354 | scoped_ptr<SpdyFrame> req_get_authorization( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4355 | spdy_util_.ConstructSpdyGet(kExtraAuthorizationHeaders, |
| 4356 | arraysize(kExtraAuthorizationHeaders) / 2, |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4357 | 3, |
| 4358 | LOWEST, |
| 4359 | false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4360 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4361 | CreateMockWrite(*req_get, 0), CreateMockWrite(*req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4362 | }; |
| 4363 | |
| 4364 | // The first response is a 407 proxy authentication challenge, and the second |
| 4365 | // response will be a 200 response since the second request includes a valid |
| 4366 | // Authorization header. |
| 4367 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4368 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4369 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4370 | scoped_ptr<SpdyFrame> resp_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4371 | spdy_util_.ConstructSpdySynReplyError( |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4372 | "407 Proxy Authentication Required", |
| 4373 | kExtraAuthenticationHeaders, arraysize(kExtraAuthenticationHeaders)/2, |
| 4374 | 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4375 | scoped_ptr<SpdyFrame> body_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4376 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 4377 | scoped_ptr<SpdyFrame> resp_data( |
| 4378 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 4379 | scoped_ptr<SpdyFrame> body_data(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4380 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4381 | CreateMockRead(*resp_authentication, 1), |
| 4382 | CreateMockRead(*body_authentication, 2), |
| 4383 | CreateMockRead(*resp_data, 4), |
| 4384 | CreateMockRead(*body_data, 5), |
| 4385 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4386 | }; |
| 4387 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4388 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4389 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4390 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4391 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4392 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4393 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4394 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4395 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4396 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4397 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4398 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4399 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4400 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4401 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4402 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4403 | |
| 4404 | rv = callback1.WaitForResult(); |
| 4405 | EXPECT_EQ(OK, rv); |
| 4406 | |
| 4407 | const HttpResponseInfo* const response = trans->GetResponseInfo(); |
| 4408 | |
| 4409 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4410 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4411 | EXPECT_EQ(407, response->headers->response_code()); |
| 4412 | EXPECT_TRUE(response->was_fetched_via_spdy); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4413 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4414 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4415 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4416 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4417 | rv = trans->RestartWithAuth( |
| 4418 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4419 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4420 | |
| 4421 | rv = callback2.WaitForResult(); |
| 4422 | EXPECT_EQ(OK, rv); |
| 4423 | |
| 4424 | const HttpResponseInfo* const response_restart = trans->GetResponseInfo(); |
| 4425 | |
| 4426 | ASSERT_TRUE(response_restart != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4427 | ASSERT_TRUE(response_restart->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4428 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 4429 | // The password prompt info should not be set. |
| 4430 | EXPECT_TRUE(response_restart->auth_challenge.get() == NULL); |
| 4431 | } |
| 4432 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4433 | // 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] | 4434 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4435 | HttpRequestInfo request; |
| 4436 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4437 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4438 | request.load_flags = 0; |
| 4439 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4440 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4441 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4442 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4443 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4444 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4445 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4446 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4447 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4448 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4449 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4450 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4451 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4452 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4453 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4454 | const char get[] = |
| 4455 | "GET / HTTP/1.1\r\n" |
| 4456 | "Host: www.example.org\r\n" |
| 4457 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4458 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4459 | spdy_util_.ConstructSpdyBodyFrame(1, get, strlen(get), false)); |
| 4460 | scoped_ptr<SpdyFrame> conn_resp( |
| 4461 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4462 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 4463 | "Content-Length: 10\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4464 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4465 | spdy_util_.ConstructSpdyBodyFrame(1, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4466 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4467 | spdy_util_.ConstructSpdyBodyFrame(1, "1234567890", 10, false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4468 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4469 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4470 | |
| 4471 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4472 | CreateMockWrite(*connect, 0), |
| 4473 | CreateMockWrite(*wrapped_get, 2), |
| 4474 | CreateMockWrite(*window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4475 | }; |
| 4476 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4477 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4478 | CreateMockRead(*conn_resp, 1, ASYNC), |
| 4479 | CreateMockRead(*wrapped_get_resp, 3, ASYNC), |
| 4480 | CreateMockRead(*wrapped_body, 4, ASYNC), |
| 4481 | CreateMockRead(*wrapped_body, 5, ASYNC), |
| 4482 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4483 | }; |
| 4484 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4485 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4486 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4487 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4488 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4489 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4490 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4491 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4492 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4493 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4494 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4495 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4496 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4497 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4498 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4499 | |
| 4500 | rv = callback1.WaitForResult(); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4501 | ASSERT_EQ(OK, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4502 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4503 | LoadTimingInfo load_timing_info; |
| 4504 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4505 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4506 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4507 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4508 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4509 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4510 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4511 | |
| 4512 | std::string response_data; |
| 4513 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 4514 | EXPECT_EQ("1234567890", response_data); |
| 4515 | } |
| 4516 | |
| 4517 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4518 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4519 | SpdyTestUtil spdy_util_wrapped(GetProtocol(), GetDependenciesFromPriority()); |
| 4520 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4521 | HttpRequestInfo request; |
| 4522 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4523 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4524 | request.load_flags = 0; |
| 4525 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4526 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4527 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4528 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4529 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4530 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4531 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4532 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4533 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4534 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4535 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4536 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4537 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4538 | // fetch https://www.example.org/ via SPDY |
| 4539 | const char kMyUrl[] = "https://www.example.org/"; |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4540 | scoped_ptr<SpdyFrame> get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4541 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4542 | scoped_ptr<SpdyFrame> wrapped_get( |
| 4543 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 4544 | scoped_ptr<SpdyFrame> conn_resp( |
| 4545 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4546 | scoped_ptr<SpdyFrame> get_resp( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4547 | spdy_util_wrapped.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4548 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4549 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4550 | scoped_ptr<SpdyFrame> body(spdy_util_wrapped.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4551 | scoped_ptr<SpdyFrame> wrapped_body( |
| 4552 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4553 | scoped_ptr<SpdyFrame> window_update_get_resp( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4554 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4555 | scoped_ptr<SpdyFrame> window_update_body( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4556 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4557 | |
| 4558 | MockWrite spdy_writes[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4559 | CreateMockWrite(*connect, 0), |
| 4560 | CreateMockWrite(*wrapped_get, 2), |
| 4561 | CreateMockWrite(*window_update_get_resp, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4562 | CreateMockWrite(*window_update_body, 7), |
| 4563 | }; |
| 4564 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4565 | MockRead spdy_reads[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4566 | CreateMockRead(*conn_resp, 1, ASYNC), |
| 4567 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4568 | CreateMockRead(*wrapped_get_resp, 4, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4569 | CreateMockRead(*wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4570 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4571 | }; |
| 4572 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4573 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4574 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4575 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4576 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4577 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4578 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4579 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4580 | SSLSocketDataProvider ssl2(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4581 | ssl2.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4582 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4583 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4584 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4585 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4586 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4587 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4588 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4589 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 4590 | base::MessageLoop::current()->RunUntilIdle(); |
| 4591 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 4592 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4593 | rv = callback1.WaitForResult(); |
| 4594 | EXPECT_EQ(OK, rv); |
| 4595 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4596 | LoadTimingInfo load_timing_info; |
| 4597 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4598 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4599 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4600 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4601 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4602 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4603 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4604 | |
| 4605 | std::string response_data; |
| 4606 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4607 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4608 | } |
| 4609 | |
| 4610 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4611 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4612 | HttpRequestInfo request; |
| 4613 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4614 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4615 | request.load_flags = 0; |
| 4616 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4617 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4618 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4619 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4620 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4621 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4622 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4623 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4624 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4625 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4626 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4627 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4628 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4629 | scoped_ptr<SpdyFrame> get( |
| 4630 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4631 | |
| 4632 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4633 | CreateMockWrite(*connect, 0), CreateMockWrite(*get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4634 | }; |
| 4635 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4636 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdySynReplyError(1)); |
| 4637 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4638 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4639 | CreateMockRead(*resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4640 | }; |
| 4641 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4642 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4643 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4644 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4645 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4646 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4647 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4648 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4649 | SSLSocketDataProvider ssl2(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4650 | ssl2.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4651 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4652 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4653 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4654 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4655 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4656 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4657 | |
| 4658 | rv = callback1.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 4659 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4660 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 4661 | // TODO(ttuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4662 | } |
| 4663 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4664 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 4665 | // HTTPS Proxy to different servers. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4666 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4667 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 4668 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4669 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4670 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4671 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4672 | scoped_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4673 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4674 | |
| 4675 | HttpRequestInfo request1; |
| 4676 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4677 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4678 | request1.load_flags = 0; |
| 4679 | |
| 4680 | HttpRequestInfo request2; |
| 4681 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4682 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4683 | request2.load_flags = 0; |
| 4684 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4685 | // CONNECT to www.example.org:443 via SPDY. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4686 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4687 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4688 | scoped_ptr<SpdyFrame> conn_resp1( |
| 4689 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4690 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4691 | // Fetch https://www.example.org/ via HTTP. |
| 4692 | const char get1[] = |
| 4693 | "GET / HTTP/1.1\r\n" |
| 4694 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4695 | "Connection: keep-alive\r\n\r\n"; |
| 4696 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4697 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4698 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 4699 | "Content-Length: 1\r\n\r\n"; |
| 4700 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4701 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 4702 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 4703 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4704 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4705 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4706 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4707 | // CONNECT to mail.example.org:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4708 | SpdyHeaderBlock connect2_block; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 4709 | spdy_util_.MaybeAddVersionHeader(&connect2_block); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4710 | connect2_block[spdy_util_.GetMethodKey()] = "CONNECT"; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4711 | if (GetProtocol() == kProtoHTTP2) { |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 4712 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org:443"; |
| 4713 | } else { |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 4714 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 4715 | connect2_block[spdy_util_.GetPathKey()] = "mail.example.org:443"; |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 4716 | } |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4717 | scoped_ptr<SpdyFrame> connect2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4718 | spdy_util_.ConstructSpdySyn(3, connect2_block, LOWEST, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 4719 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4720 | scoped_ptr<SpdyFrame> conn_resp2( |
| 4721 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4722 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4723 | // Fetch https://mail.example.org/ via HTTP. |
| 4724 | const char get2[] = |
| 4725 | "GET / HTTP/1.1\r\n" |
| 4726 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4727 | "Connection: keep-alive\r\n\r\n"; |
| 4728 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4729 | spdy_util_.ConstructSpdyBodyFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4730 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 4731 | "Content-Length: 2\r\n\r\n"; |
| 4732 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4733 | spdy_util_.ConstructSpdyBodyFrame(3, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4734 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4735 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4736 | |
| 4737 | MockWrite spdy_writes[] = { |
| 4738 | CreateMockWrite(*connect1, 0), |
| 4739 | CreateMockWrite(*wrapped_get1, 2), |
| 4740 | CreateMockWrite(*connect2, 5), |
| 4741 | CreateMockWrite(*wrapped_get2, 7), |
| 4742 | }; |
| 4743 | |
| 4744 | MockRead spdy_reads[] = { |
| 4745 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 4746 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 4747 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 4748 | CreateMockRead(*conn_resp2, 6, ASYNC), |
| 4749 | CreateMockRead(*wrapped_get_resp2, 8, ASYNC), |
| 4750 | CreateMockRead(*wrapped_body2, 9, ASYNC), |
| 4751 | MockRead(ASYNC, 0, 10), |
| 4752 | }; |
| 4753 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4754 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4755 | arraysize(spdy_writes)); |
| 4756 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4757 | |
| 4758 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4759 | ssl.SetNextProto(GetProtocol()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4760 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4761 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4762 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4763 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4764 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4765 | |
| 4766 | TestCompletionCallback callback; |
| 4767 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4768 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4769 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4770 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4771 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4772 | |
| 4773 | LoadTimingInfo load_timing_info; |
| 4774 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4775 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4776 | |
| 4777 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4778 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4779 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4780 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4781 | |
| 4782 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4783 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4784 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 4785 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4786 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4787 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4788 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4789 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4790 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4791 | |
| 4792 | LoadTimingInfo load_timing_info2; |
| 4793 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4794 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 4795 | // to be created, so the socket's load timing looks like a fresh connection. |
| 4796 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4797 | |
| 4798 | // The requests should have different IDs, since they each are using their own |
| 4799 | // separate stream. |
| 4800 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4801 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4802 | rv = trans2->Read(buf.get(), 256, callback.callback()); |
| 4803 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4804 | } |
| 4805 | |
| 4806 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 4807 | // HTTPS Proxy to the same server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4808 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4809 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 4810 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4811 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4812 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4813 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4814 | scoped_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4815 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4816 | |
| 4817 | HttpRequestInfo request1; |
| 4818 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4819 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4820 | request1.load_flags = 0; |
| 4821 | |
| 4822 | HttpRequestInfo request2; |
| 4823 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4824 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4825 | request2.load_flags = 0; |
| 4826 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4827 | // CONNECT to www.example.org:443 via SPDY. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4828 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4829 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4830 | scoped_ptr<SpdyFrame> conn_resp1( |
| 4831 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4832 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4833 | // Fetch https://www.example.org/ via HTTP. |
| 4834 | const char get1[] = |
| 4835 | "GET / HTTP/1.1\r\n" |
| 4836 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4837 | "Connection: keep-alive\r\n\r\n"; |
| 4838 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4839 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4840 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 4841 | "Content-Length: 1\r\n\r\n"; |
| 4842 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4843 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 4844 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 4845 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4846 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4847 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4848 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4849 | // Fetch https://www.example.org/2 via HTTP. |
| 4850 | const char get2[] = |
| 4851 | "GET /2 HTTP/1.1\r\n" |
| 4852 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4853 | "Connection: keep-alive\r\n\r\n"; |
| 4854 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4855 | spdy_util_.ConstructSpdyBodyFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4856 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 4857 | "Content-Length: 2\r\n\r\n"; |
| 4858 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4859 | spdy_util_.ConstructSpdyBodyFrame(1, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4860 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4861 | spdy_util_.ConstructSpdyBodyFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4862 | |
| 4863 | MockWrite spdy_writes[] = { |
| 4864 | CreateMockWrite(*connect1, 0), |
| 4865 | CreateMockWrite(*wrapped_get1, 2), |
| 4866 | CreateMockWrite(*wrapped_get2, 5), |
| 4867 | }; |
| 4868 | |
| 4869 | MockRead spdy_reads[] = { |
| 4870 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 4871 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 4872 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 4873 | CreateMockRead(*wrapped_get_resp2, 6, ASYNC), |
| 4874 | CreateMockRead(*wrapped_body2, 7, ASYNC), |
| 4875 | MockRead(ASYNC, 0, 8), |
| 4876 | }; |
| 4877 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4878 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4879 | arraysize(spdy_writes)); |
| 4880 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4881 | |
| 4882 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4883 | ssl.SetNextProto(GetProtocol()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4884 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4885 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4886 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4887 | |
| 4888 | TestCompletionCallback callback; |
| 4889 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4890 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4891 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4892 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 4893 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4894 | |
| 4895 | rv = callback.WaitForResult(); |
| 4896 | EXPECT_EQ(OK, rv); |
| 4897 | |
| 4898 | LoadTimingInfo load_timing_info; |
| 4899 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4900 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4901 | |
| 4902 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4903 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4904 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4905 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4906 | |
| 4907 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4908 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4909 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4910 | trans.reset(); |
| 4911 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4912 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4913 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4914 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 4915 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4916 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4917 | rv = callback.WaitForResult(); |
| 4918 | EXPECT_EQ(OK, rv); |
| 4919 | |
| 4920 | LoadTimingInfo load_timing_info2; |
| 4921 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4922 | TestLoadTimingReused(load_timing_info2); |
| 4923 | |
| 4924 | // The requests should have the same ID. |
| 4925 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4926 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4927 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4928 | } |
| 4929 | |
| 4930 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 4931 | // Proxy to different servers. |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4932 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4933 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4934 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4935 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4936 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4937 | scoped_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4938 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4939 | |
| 4940 | HttpRequestInfo request1; |
| 4941 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4942 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4943 | request1.load_flags = 0; |
| 4944 | |
| 4945 | HttpRequestInfo request2; |
| 4946 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4947 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4948 | request2.load_flags = 0; |
| 4949 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4950 | // http://www.example.org/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4951 | scoped_ptr<SpdyHeaderBlock> headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4952 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4953 | scoped_ptr<SpdyFrame> get1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4954 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4955 | scoped_ptr<SpdyFrame> get_resp1( |
| 4956 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4957 | scoped_ptr<SpdyFrame> body1( |
| 4958 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4959 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4960 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4961 | // http://mail.example.org/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4962 | scoped_ptr<SpdyHeaderBlock> headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4963 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4964 | scoped_ptr<SpdyFrame> get2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4965 | spdy_util_.ConstructSpdySyn(3, *headers2, LOWEST, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4966 | scoped_ptr<SpdyFrame> get_resp2( |
| 4967 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 4968 | scoped_ptr<SpdyFrame> body2( |
| 4969 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4970 | |
| 4971 | MockWrite spdy_writes[] = { |
| 4972 | CreateMockWrite(*get1, 0), |
| 4973 | CreateMockWrite(*get2, 3), |
| 4974 | }; |
| 4975 | |
| 4976 | MockRead spdy_reads[] = { |
| 4977 | CreateMockRead(*get_resp1, 1, ASYNC), |
| 4978 | CreateMockRead(*body1, 2, ASYNC), |
| 4979 | CreateMockRead(*get_resp2, 4, ASYNC), |
| 4980 | CreateMockRead(*body2, 5, ASYNC), |
| 4981 | MockRead(ASYNC, 0, 6), |
| 4982 | }; |
| 4983 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4984 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4985 | arraysize(spdy_writes)); |
| 4986 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4987 | |
| 4988 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4989 | ssl.SetNextProto(GetProtocol()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4990 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4991 | |
| 4992 | TestCompletionCallback callback; |
| 4993 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4994 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4995 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4996 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4997 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4998 | |
| 4999 | LoadTimingInfo load_timing_info; |
| 5000 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5001 | TestLoadTimingNotReused(load_timing_info, |
| 5002 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5003 | |
| 5004 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5005 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5006 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5007 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5008 | |
| 5009 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5010 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5011 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5012 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5013 | // Delete the first request, so the second one can reuse the socket. |
| 5014 | trans.reset(); |
| 5015 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5016 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5017 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5018 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5019 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5020 | |
| 5021 | LoadTimingInfo load_timing_info2; |
| 5022 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5023 | TestLoadTimingReused(load_timing_info2); |
| 5024 | |
| 5025 | // The requests should have the same ID. |
| 5026 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5027 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5028 | rv = trans2->Read(buf.get(), 256, callback.callback()); |
| 5029 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5030 | } |
| 5031 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5032 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5033 | TEST_P(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5034 | HttpRequestInfo request; |
| 5035 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5036 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5037 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5038 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5039 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5040 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5041 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5042 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5043 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5044 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5045 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5046 | // Since we have proxy, should use full url |
| 5047 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5048 | MockWrite( |
| 5049 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5050 | "Host: www.example.org\r\n" |
| 5051 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5052 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5053 | // After calling trans->RestartWithAuth(), this is the request we should |
| 5054 | // be issuing -- the final header line contains the credentials. |
| 5055 | MockWrite( |
| 5056 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5057 | "Host: www.example.org\r\n" |
| 5058 | "Proxy-Connection: keep-alive\r\n" |
| 5059 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5060 | }; |
| 5061 | |
| 5062 | // The proxy responds to the GET with a 407, using a persistent |
| 5063 | // connection. |
| 5064 | MockRead data_reads1[] = { |
| 5065 | // No credentials. |
| 5066 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5067 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5068 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 5069 | MockRead("Content-Length: 0\r\n\r\n"), |
| 5070 | |
| 5071 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5072 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5073 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5074 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5075 | }; |
| 5076 | |
| 5077 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5078 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5079 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5080 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5081 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5082 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5083 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5084 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5085 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5086 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5087 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5088 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5089 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5090 | |
| 5091 | rv = callback1.WaitForResult(); |
| 5092 | EXPECT_EQ(OK, rv); |
| 5093 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5094 | LoadTimingInfo load_timing_info; |
| 5095 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5096 | TestLoadTimingNotReused(load_timing_info, |
| 5097 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5098 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5099 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5100 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5101 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5102 | EXPECT_EQ(407, response->headers->response_code()); |
| 5103 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5104 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5105 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5106 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5107 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5108 | rv = trans->RestartWithAuth( |
| 5109 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5110 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5111 | |
| 5112 | rv = callback2.WaitForResult(); |
| 5113 | EXPECT_EQ(OK, rv); |
| 5114 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5115 | load_timing_info = LoadTimingInfo(); |
| 5116 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5117 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 5118 | TestLoadTimingReused(load_timing_info); |
| 5119 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5120 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5121 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5122 | |
| 5123 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5124 | EXPECT_EQ(200, response->headers->response_code()); |
| 5125 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5126 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5127 | |
| 5128 | // The password prompt info should not be set. |
| 5129 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5130 | } |
| 5131 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5132 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5133 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5134 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5135 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5136 | request.url = GURL("https://www.example.org/"); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5137 | request.load_flags = 0; |
| 5138 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5139 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5140 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5141 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5142 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5143 | // Since we have proxy, should try to establish tunnel. |
| 5144 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5145 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5146 | "Host: www.example.org:443\r\n" |
| 5147 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5148 | }; |
| 5149 | |
| 5150 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 5151 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 5152 | // No response body because the test stops reading here. |
| 5153 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5154 | }; |
| 5155 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5156 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5157 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5158 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5159 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5160 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5161 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5162 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5163 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5164 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5165 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5166 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5167 | |
| 5168 | rv = callback.WaitForResult(); |
| 5169 | EXPECT_EQ(expected_status, rv); |
| 5170 | } |
| 5171 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5172 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5173 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5174 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5175 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5176 | } |
| 5177 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5178 | TEST_P(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5179 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 5180 | } |
| 5181 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5182 | TEST_P(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5183 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 5184 | } |
| 5185 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5186 | TEST_P(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5187 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 5188 | } |
| 5189 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5190 | TEST_P(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5191 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 5192 | } |
| 5193 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5194 | TEST_P(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5195 | ConnectStatusHelper( |
| 5196 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 5197 | } |
| 5198 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5199 | TEST_P(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5200 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 5201 | } |
| 5202 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5203 | TEST_P(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5204 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 5205 | } |
| 5206 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5207 | TEST_P(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5208 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 5209 | } |
| 5210 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5211 | TEST_P(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5212 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 5213 | } |
| 5214 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5215 | TEST_P(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5216 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 5217 | } |
| 5218 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5219 | TEST_P(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5220 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 5221 | } |
| 5222 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5223 | TEST_P(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5224 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 5225 | } |
| 5226 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5227 | TEST_P(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5228 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 5229 | } |
| 5230 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5231 | TEST_P(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5232 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 5233 | } |
| 5234 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5235 | TEST_P(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5236 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 5237 | } |
| 5238 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5239 | TEST_P(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5240 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 5241 | } |
| 5242 | |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 5243 | TEST_P(HttpNetworkTransactionTest, ConnectStatus308) { |
| 5244 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 5245 | } |
| 5246 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5247 | TEST_P(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5248 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 5249 | } |
| 5250 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5251 | TEST_P(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5252 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 5253 | } |
| 5254 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5255 | TEST_P(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5256 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 5257 | } |
| 5258 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5259 | TEST_P(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5260 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 5261 | } |
| 5262 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5263 | TEST_P(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5264 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 5265 | } |
| 5266 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5267 | TEST_P(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5268 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 5269 | } |
| 5270 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5271 | TEST_P(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5272 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 5273 | } |
| 5274 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5275 | TEST_P(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5276 | ConnectStatusHelperWithExpectedStatus( |
| 5277 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 5278 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5279 | } |
| 5280 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5281 | TEST_P(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5282 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 5283 | } |
| 5284 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5285 | TEST_P(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5286 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 5287 | } |
| 5288 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5289 | TEST_P(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5290 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 5291 | } |
| 5292 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5293 | TEST_P(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5294 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 5295 | } |
| 5296 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5297 | TEST_P(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5298 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 5299 | } |
| 5300 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5301 | TEST_P(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5302 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 5303 | } |
| 5304 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5305 | TEST_P(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5306 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 5307 | } |
| 5308 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5309 | TEST_P(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5310 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 5311 | } |
| 5312 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5313 | TEST_P(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5314 | ConnectStatusHelper( |
| 5315 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 5316 | } |
| 5317 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5318 | TEST_P(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5319 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 5320 | } |
| 5321 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5322 | TEST_P(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5323 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 5324 | } |
| 5325 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5326 | TEST_P(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5327 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 5328 | } |
| 5329 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5330 | TEST_P(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5331 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 5332 | } |
| 5333 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5334 | TEST_P(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5335 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 5336 | } |
| 5337 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5338 | TEST_P(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5339 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 5340 | } |
| 5341 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5342 | TEST_P(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5343 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 5344 | } |
| 5345 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5346 | // Test the flow when both the proxy server AND origin server require |
| 5347 | // authentication. Again, this uses basic auth for both since that is |
| 5348 | // the simplest to mock. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5349 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5350 | HttpRequestInfo request; |
| 5351 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5352 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5353 | request.load_flags = 0; |
| 5354 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5355 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5356 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5357 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5358 | |
| 5359 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5360 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5361 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5362 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5363 | MockWrite( |
| 5364 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5365 | "Host: www.example.org\r\n" |
| 5366 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5367 | }; |
| 5368 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5369 | MockRead data_reads1[] = { |
| 5370 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 5371 | // Give a couple authenticate options (only the middle one is actually |
| 5372 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 5373 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5374 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5375 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 5376 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5377 | // Large content-length -- won't matter, as connection will be reset. |
| 5378 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5379 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5380 | }; |
| 5381 | |
| 5382 | // After calling trans->RestartWithAuth() the first time, this is the |
| 5383 | // request we should be issuing -- the final header line contains the |
| 5384 | // proxy's credentials. |
| 5385 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5386 | MockWrite( |
| 5387 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5388 | "Host: www.example.org\r\n" |
| 5389 | "Proxy-Connection: keep-alive\r\n" |
| 5390 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5391 | }; |
| 5392 | |
| 5393 | // Now the proxy server lets the request pass through to origin server. |
| 5394 | // The origin server responds with a 401. |
| 5395 | MockRead data_reads2[] = { |
| 5396 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5397 | // Note: We are using the same realm-name as the proxy server. This is |
| 5398 | // completely valid, as realms are unique across hosts. |
| 5399 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5400 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5401 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5402 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5403 | }; |
| 5404 | |
| 5405 | // After calling trans->RestartWithAuth() the second time, we should send |
| 5406 | // the credentials for both the proxy and origin server. |
| 5407 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5408 | MockWrite( |
| 5409 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5410 | "Host: www.example.org\r\n" |
| 5411 | "Proxy-Connection: keep-alive\r\n" |
| 5412 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 5413 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5414 | }; |
| 5415 | |
| 5416 | // Lastly we get the desired content. |
| 5417 | MockRead data_reads3[] = { |
| 5418 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5419 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5420 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5421 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5422 | }; |
| 5423 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5424 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5425 | data_writes1, arraysize(data_writes1)); |
| 5426 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5427 | data_writes2, arraysize(data_writes2)); |
| 5428 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5429 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5430 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5431 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5432 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5433 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5434 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5435 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5436 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5437 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5438 | |
| 5439 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5440 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5441 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5442 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5443 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5444 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5445 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5446 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5447 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5448 | rv = trans->RestartWithAuth( |
| 5449 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5450 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5451 | |
| 5452 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5453 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5454 | |
| 5455 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5456 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5457 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5458 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5459 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5460 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5461 | rv = trans->RestartWithAuth( |
| 5462 | AuthCredentials(kFoo2, kBar2), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5463 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5464 | |
| 5465 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5466 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5467 | |
| 5468 | response = trans->GetResponseInfo(); |
| 5469 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5470 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5471 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5472 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5473 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 5474 | // can't hook into its internals to cause it to generate predictable NTLM |
| 5475 | // authorization headers. |
| 5476 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5477 | // The NTLM authentication unit tests were generated by capturing the HTTP |
| 5478 | // requests and responses using Fiddler 2 and inspecting the generated random |
| 5479 | // bytes in the debugger. |
| 5480 | |
| 5481 | // Enter the correct password and authenticate successfully. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5482 | TEST_P(HttpNetworkTransactionTest, NTLMAuth1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5483 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5484 | request.method = "GET"; |
| 5485 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5486 | |
| 5487 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 5488 | // to other auth schemes. |
| 5489 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5490 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5491 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 5492 | MockGetHostName); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5493 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5494 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5495 | MockWrite data_writes1[] = { |
| 5496 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5497 | "Host: 172.22.68.17\r\n" |
| 5498 | "Connection: keep-alive\r\n\r\n"), |
| 5499 | }; |
| 5500 | |
| 5501 | MockRead data_reads1[] = { |
| 5502 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 5503 | // Negotiate and NTLM are often requested together. However, we only want |
| 5504 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 5505 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5506 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5507 | MockRead("Connection: close\r\n"), |
| 5508 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5509 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5510 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5511 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5512 | }; |
| 5513 | |
| 5514 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5515 | // After restarting with a null identity, this is the |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5516 | // request we should be issuing -- the final header line contains a Type |
| 5517 | // 1 message. |
| 5518 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5519 | "Host: 172.22.68.17\r\n" |
| 5520 | "Connection: keep-alive\r\n" |
| 5521 | "Authorization: NTLM " |
| 5522 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 5523 | |
| 5524 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 5525 | // (the credentials for the origin server). The second request continues |
| 5526 | // on the same connection. |
| 5527 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5528 | "Host: 172.22.68.17\r\n" |
| 5529 | "Connection: keep-alive\r\n" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5530 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5531 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5532 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 5533 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 5534 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5535 | }; |
| 5536 | |
| 5537 | MockRead data_reads2[] = { |
| 5538 | // The origin server responds with a Type 2 message. |
| 5539 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5540 | MockRead("WWW-Authenticate: NTLM " |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5541 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5542 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5543 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5544 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5545 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5546 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5547 | "BtAAAAAAA=\r\n"), |
| 5548 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5549 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5550 | MockRead("You are not authorized to view this page\r\n"), |
| 5551 | |
| 5552 | // Lastly we get the desired content. |
| 5553 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5554 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 5555 | MockRead("Content-Length: 13\r\n\r\n"), |
| 5556 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5557 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5558 | }; |
| 5559 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5560 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5561 | data_writes1, arraysize(data_writes1)); |
| 5562 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5563 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5564 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5565 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5566 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5567 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5568 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5569 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5570 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5571 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5572 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5573 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5574 | |
| 5575 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5576 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5577 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5578 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5579 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5580 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5581 | ASSERT_FALSE(response == NULL); |
| 5582 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5583 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5584 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5585 | |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5586 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5587 | callback2.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5588 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5589 | |
| 5590 | rv = callback2.WaitForResult(); |
| 5591 | EXPECT_EQ(OK, rv); |
| 5592 | |
| 5593 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5594 | |
| 5595 | response = trans->GetResponseInfo(); |
| 5596 | ASSERT_TRUE(response != NULL); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5597 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5598 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5599 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5600 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5601 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5602 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5603 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5604 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5605 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5606 | |
| 5607 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5608 | ASSERT_TRUE(response != NULL); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5609 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5610 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 5611 | } |
| 5612 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5613 | // Enter a wrong password, and then the correct one. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5614 | TEST_P(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5615 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5616 | request.method = "GET"; |
| 5617 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 5618 | request.load_flags = 0; |
| 5619 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5620 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 5621 | MockGetHostName); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5622 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5623 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5624 | MockWrite data_writes1[] = { |
| 5625 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5626 | "Host: 172.22.68.17\r\n" |
| 5627 | "Connection: keep-alive\r\n\r\n"), |
| 5628 | }; |
| 5629 | |
| 5630 | MockRead data_reads1[] = { |
| 5631 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 5632 | // Negotiate and NTLM are often requested together. However, we only want |
| 5633 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 5634 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5635 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5636 | MockRead("Connection: close\r\n"), |
| 5637 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5638 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5639 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5640 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5641 | }; |
| 5642 | |
| 5643 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5644 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5645 | // request we should be issuing -- the final header line contains a Type |
| 5646 | // 1 message. |
| 5647 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5648 | "Host: 172.22.68.17\r\n" |
| 5649 | "Connection: keep-alive\r\n" |
| 5650 | "Authorization: NTLM " |
| 5651 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 5652 | |
| 5653 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 5654 | // (the credentials for the origin server). The second request continues |
| 5655 | // on the same connection. |
| 5656 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5657 | "Host: 172.22.68.17\r\n" |
| 5658 | "Connection: keep-alive\r\n" |
| 5659 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5660 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5661 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 5662 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 5663 | "4Ww7b7E=\r\n\r\n"), |
| 5664 | }; |
| 5665 | |
| 5666 | MockRead data_reads2[] = { |
| 5667 | // The origin server responds with a Type 2 message. |
| 5668 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5669 | MockRead("WWW-Authenticate: NTLM " |
| 5670 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 5671 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5672 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5673 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5674 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5675 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5676 | "BtAAAAAAA=\r\n"), |
| 5677 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5678 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5679 | MockRead("You are not authorized to view this page\r\n"), |
| 5680 | |
| 5681 | // Wrong password. |
| 5682 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5683 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5684 | MockRead("Connection: close\r\n"), |
| 5685 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5686 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5687 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5688 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5689 | }; |
| 5690 | |
| 5691 | MockWrite data_writes3[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5692 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5693 | // request we should be issuing -- the final header line contains a Type |
| 5694 | // 1 message. |
| 5695 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5696 | "Host: 172.22.68.17\r\n" |
| 5697 | "Connection: keep-alive\r\n" |
| 5698 | "Authorization: NTLM " |
| 5699 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 5700 | |
| 5701 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 5702 | // (the credentials for the origin server). The second request continues |
| 5703 | // on the same connection. |
| 5704 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5705 | "Host: 172.22.68.17\r\n" |
| 5706 | "Connection: keep-alive\r\n" |
| 5707 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5708 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5709 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 5710 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 5711 | "+4MUm7c=\r\n\r\n"), |
| 5712 | }; |
| 5713 | |
| 5714 | MockRead data_reads3[] = { |
| 5715 | // The origin server responds with a Type 2 message. |
| 5716 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5717 | MockRead("WWW-Authenticate: NTLM " |
| 5718 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 5719 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5720 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5721 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5722 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5723 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5724 | "BtAAAAAAA=\r\n"), |
| 5725 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5726 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5727 | MockRead("You are not authorized to view this page\r\n"), |
| 5728 | |
| 5729 | // Lastly we get the desired content. |
| 5730 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5731 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 5732 | MockRead("Content-Length: 13\r\n\r\n"), |
| 5733 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5734 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5735 | }; |
| 5736 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5737 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5738 | data_writes1, arraysize(data_writes1)); |
| 5739 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5740 | data_writes2, arraysize(data_writes2)); |
| 5741 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5742 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5743 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5744 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5745 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5746 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5747 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5748 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5749 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5750 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5751 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5752 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5753 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5754 | |
| 5755 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5756 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5757 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5758 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5759 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5760 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5761 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5762 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5763 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5764 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5765 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5766 | // Enter the wrong password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5767 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5768 | callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5769 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5770 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5771 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5772 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5773 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5774 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5775 | TestCompletionCallback callback3; |
| 5776 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5777 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5778 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5779 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5780 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5781 | |
| 5782 | response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5783 | ASSERT_FALSE(response == NULL); |
| 5784 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5785 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5786 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5787 | |
| 5788 | // Now enter the right password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5789 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5790 | callback4.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5791 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5792 | |
| 5793 | rv = callback4.WaitForResult(); |
| 5794 | EXPECT_EQ(OK, rv); |
| 5795 | |
| 5796 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5797 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5798 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5799 | |
| 5800 | // One more roundtrip |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5801 | rv = trans->RestartWithAuth(AuthCredentials(), callback5.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5802 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5803 | |
| 5804 | rv = callback5.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5805 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5806 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5807 | response = trans->GetResponseInfo(); |
| 5808 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5809 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 5810 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5811 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5812 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5813 | // Test reading a server response which has only headers, and no body. |
| 5814 | // After some maximum number of bytes is consumed, the transaction should |
| 5815 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5816 | TEST_P(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5817 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5818 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5819 | request.url = GURL("http://www.example.org/"); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5820 | request.load_flags = 0; |
| 5821 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5822 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5823 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5824 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5825 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 5826 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 5827 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 5828 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5829 | |
| 5830 | MockRead data_reads[] = { |
| 5831 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5832 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5833 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5834 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5835 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5836 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5837 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5838 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5839 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5840 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5841 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5842 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5843 | |
| 5844 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5845 | EXPECT_EQ(ERR_RESPONSE_HEADERS_TOO_BIG, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5846 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5847 | |
| 5848 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 5849 | // establish tunnel. |
| 5850 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5851 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5852 | DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5853 | HttpRequestInfo request; |
| 5854 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5855 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5856 | request.load_flags = 0; |
| 5857 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5858 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5859 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 5860 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5861 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5862 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5863 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5864 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5865 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5866 | // Since we have proxy, should try to establish tunnel. |
| 5867 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5868 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5869 | "Host: www.example.org:443\r\n" |
| 5870 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5871 | }; |
| 5872 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 5873 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5874 | // connection. Usually a proxy would return 501 (not implemented), |
| 5875 | // or 200 (tunnel established). |
| 5876 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 5877 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 5878 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5879 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5880 | }; |
| 5881 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5882 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5883 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5884 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5885 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5886 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5887 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5888 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5889 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5890 | |
| 5891 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5892 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5893 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5894 | // Empty the current queue. This is necessary because idle sockets are |
| 5895 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5896 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5897 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5898 | // We now check to make sure the TCPClientSocket was not added back to |
| 5899 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5900 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5901 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5902 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5903 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5904 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5905 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5906 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5907 | // 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] | 5908 | TEST_P(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5909 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5910 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5911 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5912 | request.load_flags = 0; |
| 5913 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5914 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5915 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5916 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5917 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5918 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5919 | MockRead data_reads[] = { |
| 5920 | // A part of the response body is received with the response headers. |
| 5921 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 5922 | // The rest of the response body is received in two parts. |
| 5923 | MockRead("lo"), |
| 5924 | MockRead(" world"), |
| 5925 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5926 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5927 | }; |
| 5928 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5929 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5930 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5931 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5932 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5933 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5934 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5935 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5936 | |
| 5937 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5938 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5939 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5940 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5941 | ASSERT_TRUE(response != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5942 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5943 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5944 | std::string status_line = response->headers->GetStatusLine(); |
| 5945 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 5946 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5947 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5948 | |
| 5949 | std::string response_data; |
| 5950 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5951 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5952 | EXPECT_EQ("hello world", response_data); |
| 5953 | |
| 5954 | // Empty the current queue. This is necessary because idle sockets are |
| 5955 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5956 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5957 | |
| 5958 | // 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] | 5959 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5960 | } |
| 5961 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5962 | // Make sure that we recycle a SSL socket after reading all of the response |
| 5963 | // body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5964 | TEST_P(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5965 | HttpRequestInfo request; |
| 5966 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5967 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5968 | request.load_flags = 0; |
| 5969 | |
| 5970 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5971 | MockWrite( |
| 5972 | "GET / HTTP/1.1\r\n" |
| 5973 | "Host: www.example.org\r\n" |
| 5974 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5975 | }; |
| 5976 | |
| 5977 | MockRead data_reads[] = { |
| 5978 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5979 | MockRead("Content-Length: 11\r\n\r\n"), |
| 5980 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5981 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5982 | }; |
| 5983 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5984 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5985 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5986 | |
| 5987 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5988 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5989 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5990 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5991 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5992 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5993 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5994 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5995 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5996 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5997 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5998 | |
| 5999 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6000 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 6001 | |
| 6002 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6003 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6004 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6005 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6006 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6007 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6008 | |
| 6009 | std::string response_data; |
| 6010 | rv = ReadTransaction(trans.get(), &response_data); |
| 6011 | EXPECT_EQ(OK, rv); |
| 6012 | EXPECT_EQ("hello world", response_data); |
| 6013 | |
| 6014 | // Empty the current queue. This is necessary because idle sockets are |
| 6015 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 6016 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6017 | |
| 6018 | // 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] | 6019 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6020 | } |
| 6021 | |
| 6022 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 6023 | // from the pool and make sure that we recover okay. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6024 | TEST_P(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6025 | HttpRequestInfo request; |
| 6026 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6027 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6028 | request.load_flags = 0; |
| 6029 | |
| 6030 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6031 | MockWrite( |
| 6032 | "GET / HTTP/1.1\r\n" |
| 6033 | "Host: www.example.org\r\n" |
| 6034 | "Connection: keep-alive\r\n\r\n"), |
| 6035 | MockWrite( |
| 6036 | "GET / HTTP/1.1\r\n" |
| 6037 | "Host: www.example.org\r\n" |
| 6038 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6039 | }; |
| 6040 | |
| 6041 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 6042 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6043 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6044 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6045 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6046 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6047 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6048 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6049 | |
| 6050 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6051 | data_writes, arraysize(data_writes)); |
| 6052 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 6053 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6054 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6055 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6056 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6057 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6058 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6059 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6060 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6061 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6062 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6063 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6064 | |
| 6065 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6066 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 6067 | |
| 6068 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6069 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6070 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6071 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6072 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6073 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6074 | |
| 6075 | std::string response_data; |
| 6076 | rv = ReadTransaction(trans.get(), &response_data); |
| 6077 | EXPECT_EQ(OK, rv); |
| 6078 | EXPECT_EQ("hello world", response_data); |
| 6079 | |
| 6080 | // Empty the current queue. This is necessary because idle sockets are |
| 6081 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 6082 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6083 | |
| 6084 | // 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] | 6085 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6086 | |
| 6087 | // Now start the second transaction, which should reuse the previous socket. |
| 6088 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6089 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6090 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6091 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6092 | |
| 6093 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6094 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 6095 | |
| 6096 | response = trans->GetResponseInfo(); |
| 6097 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6098 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6099 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6100 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6101 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6102 | |
| 6103 | rv = ReadTransaction(trans.get(), &response_data); |
| 6104 | EXPECT_EQ(OK, rv); |
| 6105 | EXPECT_EQ("hello world", response_data); |
| 6106 | |
| 6107 | // Empty the current queue. This is necessary because idle sockets are |
| 6108 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 6109 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6110 | |
| 6111 | // 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] | 6112 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6113 | } |
| 6114 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6115 | // Make sure that we recycle a socket after a zero-length response. |
| 6116 | // http://crbug.com/9880 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6117 | TEST_P(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6118 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6119 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6120 | request.url = GURL( |
| 6121 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 6122 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 6123 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 6124 | "rt=prt.2642,ol.2649,xjs.2951"); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6125 | request.load_flags = 0; |
| 6126 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6127 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6128 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6129 | MockRead data_reads[] = { |
| 6130 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 6131 | "Content-Length: 0\r\n" |
| 6132 | "Content-Type: text/html\r\n\r\n"), |
| 6133 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6134 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6135 | }; |
| 6136 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6137 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6138 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6139 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 6140 | // Transaction must be created after the MockReads, so it's destroyed before |
| 6141 | // them. |
| 6142 | scoped_ptr<HttpTransaction> trans( |
| 6143 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 6144 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6145 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6146 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6147 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6148 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6149 | |
| 6150 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6151 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6152 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6153 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6154 | ASSERT_TRUE(response != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6155 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6156 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6157 | std::string status_line = response->headers->GetStatusLine(); |
| 6158 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 6159 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6160 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6161 | |
| 6162 | std::string response_data; |
| 6163 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6164 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6165 | EXPECT_EQ("", response_data); |
| 6166 | |
| 6167 | // Empty the current queue. This is necessary because idle sockets are |
| 6168 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 6169 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6170 | |
| 6171 | // 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] | 6172 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6173 | } |
| 6174 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6175 | TEST_P(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6176 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 6177 | element_readers.push_back( |
| 6178 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 6179 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6180 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6181 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6182 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 6183 | // after use. |
| 6184 | request[0].method = "GET"; |
| 6185 | request[0].url = GURL("http://www.google.com/"); |
| 6186 | request[0].load_flags = 0; |
| 6187 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 6188 | // transaction 1. The first attempts fails when writing the POST data. |
| 6189 | // This causes the transaction to retry with a new socket. The second |
| 6190 | // attempt succeeds. |
| 6191 | request[1].method = "POST"; |
| 6192 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6193 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6194 | request[1].load_flags = 0; |
| 6195 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6196 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6197 | |
| 6198 | // The first socket is used for transaction 1 and the first attempt of |
| 6199 | // transaction 2. |
| 6200 | |
| 6201 | // The response of transaction 1. |
| 6202 | MockRead data_reads1[] = { |
| 6203 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 6204 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6205 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6206 | }; |
| 6207 | // The mock write results of transaction 1 and the first attempt of |
| 6208 | // transaction 2. |
| 6209 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6210 | MockWrite(SYNCHRONOUS, 64), // GET |
| 6211 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6212 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6213 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6214 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6215 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6216 | |
| 6217 | // The second socket is used for the second attempt of transaction 2. |
| 6218 | |
| 6219 | // The response of transaction 2. |
| 6220 | MockRead data_reads2[] = { |
| 6221 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 6222 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6223 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6224 | }; |
| 6225 | // The mock write results of the second attempt of transaction 2. |
| 6226 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6227 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6228 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6229 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6230 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6231 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6232 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6233 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6234 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6235 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 6236 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6237 | "hello world", "welcome" |
| 6238 | }; |
| 6239 | |
| 6240 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6241 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6242 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6243 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6244 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6245 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6246 | int rv = trans->Start(&request[i], callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6247 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6248 | |
| 6249 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6250 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6251 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6252 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6253 | ASSERT_TRUE(response != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6254 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6255 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6256 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6257 | |
| 6258 | std::string response_data; |
| 6259 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6260 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6261 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 6262 | } |
| 6263 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6264 | |
| 6265 | // Test the request-challenge-retry sequence for basic auth when there is |
| 6266 | // 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] | 6267 | // it fails the identity from the URL is used to answer the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6268 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6269 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6270 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6271 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 6272 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6273 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6274 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6275 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6276 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6277 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6278 | // The password contains an escaped character -- for this test to pass it |
| 6279 | // will need to be unescaped by HttpNetworkTransaction. |
| 6280 | EXPECT_EQ("b%40r", request.url.password()); |
| 6281 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6282 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6283 | MockWrite( |
| 6284 | "GET / HTTP/1.1\r\n" |
| 6285 | "Host: www.example.org\r\n" |
| 6286 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6287 | }; |
| 6288 | |
| 6289 | MockRead data_reads1[] = { |
| 6290 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6291 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6292 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6293 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6294 | }; |
| 6295 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6296 | // After the challenge above, the transaction will be restarted using the |
| 6297 | // identity from the url (foo, b@r) to answer the challenge. |
| 6298 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6299 | MockWrite( |
| 6300 | "GET / HTTP/1.1\r\n" |
| 6301 | "Host: www.example.org\r\n" |
| 6302 | "Connection: keep-alive\r\n" |
| 6303 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6304 | }; |
| 6305 | |
| 6306 | MockRead data_reads2[] = { |
| 6307 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6308 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6309 | MockRead(SYNCHRONOUS, OK), |
| 6310 | }; |
| 6311 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6312 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6313 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6314 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6315 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6316 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6317 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6318 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6319 | TestCompletionCallback callback1; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6320 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6321 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6322 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6323 | EXPECT_EQ(OK, rv); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6324 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 6325 | |
| 6326 | TestCompletionCallback callback2; |
| 6327 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 6328 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6329 | rv = callback2.WaitForResult(); |
| 6330 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6331 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6332 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6333 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6334 | ASSERT_TRUE(response != NULL); |
| 6335 | |
| 6336 | // There is no challenge info, since the identity in URL worked. |
| 6337 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6338 | |
| 6339 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6340 | |
| 6341 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 6342 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6343 | } |
| 6344 | |
| 6345 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 6346 | // incorrect identity in the URL. The identity from the URL should be used only |
| 6347 | // once. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6348 | TEST_P(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6349 | HttpRequestInfo request; |
| 6350 | request.method = "GET"; |
| 6351 | // Note: the URL has a username:password in it. The password "baz" is |
| 6352 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6353 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6354 | |
| 6355 | request.load_flags = LOAD_NORMAL; |
| 6356 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6357 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6358 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6359 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6360 | |
| 6361 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6362 | MockWrite( |
| 6363 | "GET / HTTP/1.1\r\n" |
| 6364 | "Host: www.example.org\r\n" |
| 6365 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6366 | }; |
| 6367 | |
| 6368 | MockRead data_reads1[] = { |
| 6369 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6370 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6371 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6372 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6373 | }; |
| 6374 | |
| 6375 | // After the challenge above, the transaction will be restarted using the |
| 6376 | // identity from the url (foo, baz) to answer the challenge. |
| 6377 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6378 | MockWrite( |
| 6379 | "GET / HTTP/1.1\r\n" |
| 6380 | "Host: www.example.org\r\n" |
| 6381 | "Connection: keep-alive\r\n" |
| 6382 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6383 | }; |
| 6384 | |
| 6385 | MockRead data_reads2[] = { |
| 6386 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6387 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6388 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6389 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6390 | }; |
| 6391 | |
| 6392 | // After the challenge above, the transaction will be restarted using the |
| 6393 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 6394 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6395 | MockWrite( |
| 6396 | "GET / HTTP/1.1\r\n" |
| 6397 | "Host: www.example.org\r\n" |
| 6398 | "Connection: keep-alive\r\n" |
| 6399 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6400 | }; |
| 6401 | |
| 6402 | MockRead data_reads3[] = { |
| 6403 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6404 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6405 | MockRead(SYNCHRONOUS, OK), |
| 6406 | }; |
| 6407 | |
| 6408 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6409 | data_writes1, arraysize(data_writes1)); |
| 6410 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6411 | data_writes2, arraysize(data_writes2)); |
| 6412 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6413 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6414 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6415 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6416 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6417 | |
| 6418 | TestCompletionCallback callback1; |
| 6419 | |
| 6420 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 6421 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6422 | |
| 6423 | rv = callback1.WaitForResult(); |
| 6424 | EXPECT_EQ(OK, rv); |
| 6425 | |
| 6426 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 6427 | TestCompletionCallback callback2; |
| 6428 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 6429 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6430 | rv = callback2.WaitForResult(); |
| 6431 | EXPECT_EQ(OK, rv); |
| 6432 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6433 | |
| 6434 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6435 | ASSERT_TRUE(response != NULL); |
| 6436 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 6437 | |
| 6438 | TestCompletionCallback callback3; |
| 6439 | rv = trans->RestartWithAuth( |
| 6440 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 6441 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6442 | rv = callback3.WaitForResult(); |
| 6443 | EXPECT_EQ(OK, rv); |
| 6444 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6445 | |
| 6446 | response = trans->GetResponseInfo(); |
| 6447 | ASSERT_TRUE(response != NULL); |
| 6448 | |
| 6449 | // There is no challenge info, since the identity worked. |
| 6450 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6451 | |
| 6452 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6453 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6454 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 6455 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6456 | } |
| 6457 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6458 | |
| 6459 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 6460 | // correct identity in the URL, but its use is being suppressed. The identity |
| 6461 | // from the URL should never be used. |
| 6462 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
| 6463 | HttpRequestInfo request; |
| 6464 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6465 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6466 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 6467 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6468 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6469 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6470 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6471 | |
| 6472 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6473 | MockWrite( |
| 6474 | "GET / HTTP/1.1\r\n" |
| 6475 | "Host: www.example.org\r\n" |
| 6476 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6477 | }; |
| 6478 | |
| 6479 | MockRead data_reads1[] = { |
| 6480 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6481 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6482 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6483 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6484 | }; |
| 6485 | |
| 6486 | // After the challenge above, the transaction will be restarted using the |
| 6487 | // identity supplied by the user, not the one in the URL, to answer the |
| 6488 | // challenge. |
| 6489 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6490 | MockWrite( |
| 6491 | "GET / HTTP/1.1\r\n" |
| 6492 | "Host: www.example.org\r\n" |
| 6493 | "Connection: keep-alive\r\n" |
| 6494 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6495 | }; |
| 6496 | |
| 6497 | MockRead data_reads3[] = { |
| 6498 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6499 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6500 | MockRead(SYNCHRONOUS, OK), |
| 6501 | }; |
| 6502 | |
| 6503 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6504 | data_writes1, arraysize(data_writes1)); |
| 6505 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6506 | data_writes3, arraysize(data_writes3)); |
| 6507 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6508 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 6509 | |
| 6510 | TestCompletionCallback callback1; |
| 6511 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 6512 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6513 | rv = callback1.WaitForResult(); |
| 6514 | EXPECT_EQ(OK, rv); |
| 6515 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6516 | |
| 6517 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6518 | ASSERT_TRUE(response != NULL); |
| 6519 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 6520 | |
| 6521 | TestCompletionCallback callback3; |
| 6522 | rv = trans->RestartWithAuth( |
| 6523 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 6524 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6525 | rv = callback3.WaitForResult(); |
| 6526 | EXPECT_EQ(OK, rv); |
| 6527 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6528 | |
| 6529 | response = trans->GetResponseInfo(); |
| 6530 | ASSERT_TRUE(response != NULL); |
| 6531 | |
| 6532 | // There is no challenge info, since the identity worked. |
| 6533 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6534 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6535 | |
| 6536 | // Empty the current queue. |
| 6537 | base::MessageLoop::current()->RunUntilIdle(); |
| 6538 | } |
| 6539 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6540 | // Test that previously tried username/passwords for a realm get re-used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6541 | TEST_P(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6542 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6543 | |
| 6544 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 6545 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6546 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6547 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6548 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6549 | request.load_flags = 0; |
| 6550 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6551 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6552 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6553 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6554 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6555 | MockWrite( |
| 6556 | "GET /x/y/z HTTP/1.1\r\n" |
| 6557 | "Host: www.example.org\r\n" |
| 6558 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6559 | }; |
| 6560 | |
| 6561 | MockRead data_reads1[] = { |
| 6562 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6563 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6564 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6565 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6566 | }; |
| 6567 | |
| 6568 | // Resend with authorization (username=foo, password=bar) |
| 6569 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6570 | MockWrite( |
| 6571 | "GET /x/y/z HTTP/1.1\r\n" |
| 6572 | "Host: www.example.org\r\n" |
| 6573 | "Connection: keep-alive\r\n" |
| 6574 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6575 | }; |
| 6576 | |
| 6577 | // Sever accepts the authorization. |
| 6578 | MockRead data_reads2[] = { |
| 6579 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6580 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6581 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6582 | }; |
| 6583 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6584 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6585 | data_writes1, arraysize(data_writes1)); |
| 6586 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6587 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6588 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6589 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6590 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6591 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6592 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6593 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6594 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6595 | |
| 6596 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6597 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6598 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6599 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6600 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6601 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6602 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6603 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6604 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6605 | rv = trans->RestartWithAuth( |
| 6606 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6607 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6608 | |
| 6609 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6610 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6611 | |
| 6612 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6613 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6614 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6615 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6616 | } |
| 6617 | |
| 6618 | // ------------------------------------------------------------------------ |
| 6619 | |
| 6620 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 6621 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6622 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6623 | request.method = "GET"; |
| 6624 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 6625 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6626 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6627 | request.load_flags = 0; |
| 6628 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6629 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6630 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6631 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6632 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6633 | MockWrite( |
| 6634 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 6635 | "Host: www.example.org\r\n" |
| 6636 | "Connection: keep-alive\r\n" |
| 6637 | // Send preemptive authorization for MyRealm1 |
| 6638 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6639 | }; |
| 6640 | |
| 6641 | // The server didn't like the preemptive authorization, and |
| 6642 | // challenges us for a different realm (MyRealm2). |
| 6643 | MockRead data_reads1[] = { |
| 6644 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6645 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 6646 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6647 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6648 | }; |
| 6649 | |
| 6650 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 6651 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6652 | MockWrite( |
| 6653 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 6654 | "Host: www.example.org\r\n" |
| 6655 | "Connection: keep-alive\r\n" |
| 6656 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6657 | }; |
| 6658 | |
| 6659 | // Sever accepts the authorization. |
| 6660 | MockRead data_reads2[] = { |
| 6661 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6662 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6663 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6664 | }; |
| 6665 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6666 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6667 | data_writes1, arraysize(data_writes1)); |
| 6668 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6669 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6670 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6671 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6672 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6673 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6674 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6675 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6676 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6677 | |
| 6678 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6679 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6680 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6681 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6682 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6683 | ASSERT_TRUE(response->auth_challenge.get()); |
| 6684 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6685 | EXPECT_EQ("www.example.org:80", |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6686 | response->auth_challenge->challenger.ToString()); |
| 6687 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 6688 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6689 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6690 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6691 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6692 | rv = trans->RestartWithAuth( |
| 6693 | AuthCredentials(kFoo2, kBar2), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6694 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6695 | |
| 6696 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6697 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6698 | |
| 6699 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6700 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6701 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6702 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6703 | } |
| 6704 | |
| 6705 | // ------------------------------------------------------------------------ |
| 6706 | |
| 6707 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 6708 | // succeed with preemptive authorization. |
| 6709 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6710 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6711 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6712 | request.url = GURL("http://www.example.org/x/y/z2"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6713 | request.load_flags = 0; |
| 6714 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6715 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6716 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6717 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6718 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6719 | MockWrite( |
| 6720 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 6721 | "Host: www.example.org\r\n" |
| 6722 | "Connection: keep-alive\r\n" |
| 6723 | // The authorization for MyRealm1 gets sent preemptively |
| 6724 | // (since the url is in the same protection space) |
| 6725 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6726 | }; |
| 6727 | |
| 6728 | // Sever accepts the preemptive authorization |
| 6729 | MockRead data_reads1[] = { |
| 6730 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6731 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6732 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6733 | }; |
| 6734 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6735 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6736 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6737 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6738 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6739 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6740 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6741 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6742 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6743 | |
| 6744 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6745 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6746 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6747 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6748 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6749 | |
| 6750 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6751 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6752 | } |
| 6753 | |
| 6754 | // ------------------------------------------------------------------------ |
| 6755 | |
| 6756 | // Transaction 4: request another URL in MyRealm (however the |
| 6757 | // url is not known to belong to the protection space, so no pre-auth). |
| 6758 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6759 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6760 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6761 | request.url = GURL("http://www.example.org/x/1"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6762 | request.load_flags = 0; |
| 6763 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6764 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6765 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6766 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6767 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6768 | MockWrite( |
| 6769 | "GET /x/1 HTTP/1.1\r\n" |
| 6770 | "Host: www.example.org\r\n" |
| 6771 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6772 | }; |
| 6773 | |
| 6774 | MockRead data_reads1[] = { |
| 6775 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6776 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6777 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6778 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6779 | }; |
| 6780 | |
| 6781 | // Resend with authorization from MyRealm's cache. |
| 6782 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6783 | MockWrite( |
| 6784 | "GET /x/1 HTTP/1.1\r\n" |
| 6785 | "Host: www.example.org\r\n" |
| 6786 | "Connection: keep-alive\r\n" |
| 6787 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6788 | }; |
| 6789 | |
| 6790 | // Sever accepts the authorization. |
| 6791 | MockRead data_reads2[] = { |
| 6792 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6793 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6794 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6795 | }; |
| 6796 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6797 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6798 | data_writes1, arraysize(data_writes1)); |
| 6799 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6800 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6801 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6802 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6803 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6804 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6805 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6806 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6807 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6808 | |
| 6809 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6810 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6811 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6812 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6813 | TestCompletionCallback callback2; |
| 6814 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6815 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6816 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6817 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6818 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6819 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6820 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6821 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6822 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6823 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6824 | } |
| 6825 | |
| 6826 | // ------------------------------------------------------------------------ |
| 6827 | |
| 6828 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 6829 | // cached identity. Should invalidate and re-prompt. |
| 6830 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6831 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6832 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6833 | request.url = GURL("http://www.example.org/p/q/t"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6834 | request.load_flags = 0; |
| 6835 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6836 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6837 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6838 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6839 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6840 | MockWrite( |
| 6841 | "GET /p/q/t HTTP/1.1\r\n" |
| 6842 | "Host: www.example.org\r\n" |
| 6843 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6844 | }; |
| 6845 | |
| 6846 | MockRead data_reads1[] = { |
| 6847 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6848 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6849 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6850 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6851 | }; |
| 6852 | |
| 6853 | // Resend with authorization from cache for MyRealm. |
| 6854 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6855 | MockWrite( |
| 6856 | "GET /p/q/t HTTP/1.1\r\n" |
| 6857 | "Host: www.example.org\r\n" |
| 6858 | "Connection: keep-alive\r\n" |
| 6859 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6860 | }; |
| 6861 | |
| 6862 | // Sever rejects the authorization. |
| 6863 | MockRead data_reads2[] = { |
| 6864 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6865 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6866 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6867 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6868 | }; |
| 6869 | |
| 6870 | // At this point we should prompt for new credentials for MyRealm. |
| 6871 | // Restart with username=foo3, password=foo4. |
| 6872 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6873 | MockWrite( |
| 6874 | "GET /p/q/t HTTP/1.1\r\n" |
| 6875 | "Host: www.example.org\r\n" |
| 6876 | "Connection: keep-alive\r\n" |
| 6877 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6878 | }; |
| 6879 | |
| 6880 | // Sever accepts the authorization. |
| 6881 | MockRead data_reads3[] = { |
| 6882 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6883 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6884 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6885 | }; |
| 6886 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6887 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6888 | data_writes1, arraysize(data_writes1)); |
| 6889 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6890 | data_writes2, arraysize(data_writes2)); |
| 6891 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6892 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6893 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6894 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6895 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6896 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6897 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6898 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6899 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6900 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6901 | |
| 6902 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6903 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6904 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6905 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6906 | TestCompletionCallback callback2; |
| 6907 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6908 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6909 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6910 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6911 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6912 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6913 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6914 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6915 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6916 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6917 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6918 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6919 | rv = trans->RestartWithAuth( |
| 6920 | AuthCredentials(kFoo3, kBar3), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6921 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6922 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6923 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6924 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6925 | |
| 6926 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6927 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6928 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6929 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6930 | } |
| 6931 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6932 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6933 | // Tests that nonce count increments when multiple auth attempts |
| 6934 | // are started with the same nonce. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6935 | TEST_P(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 6936 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 6937 | new HttpAuthHandlerDigest::Factory(); |
| 6938 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 6939 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 6940 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6941 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6942 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6943 | |
| 6944 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 6945 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6946 | HttpRequestInfo request; |
| 6947 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6948 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6949 | request.load_flags = 0; |
| 6950 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6951 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6952 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6953 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6954 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6955 | MockWrite( |
| 6956 | "GET /x/y/z HTTP/1.1\r\n" |
| 6957 | "Host: www.example.org\r\n" |
| 6958 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6959 | }; |
| 6960 | |
| 6961 | MockRead data_reads1[] = { |
| 6962 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6963 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 6964 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6965 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6966 | }; |
| 6967 | |
| 6968 | // Resend with authorization (username=foo, password=bar) |
| 6969 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6970 | MockWrite( |
| 6971 | "GET /x/y/z HTTP/1.1\r\n" |
| 6972 | "Host: www.example.org\r\n" |
| 6973 | "Connection: keep-alive\r\n" |
| 6974 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 6975 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 6976 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 6977 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6978 | }; |
| 6979 | |
| 6980 | // Sever accepts the authorization. |
| 6981 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 6982 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6983 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6984 | }; |
| 6985 | |
| 6986 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6987 | data_writes1, arraysize(data_writes1)); |
| 6988 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6989 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6990 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6991 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6992 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6993 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6994 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6995 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6996 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6997 | |
| 6998 | rv = callback1.WaitForResult(); |
| 6999 | EXPECT_EQ(OK, rv); |
| 7000 | |
| 7001 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7002 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7003 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7004 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7005 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7006 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7007 | rv = trans->RestartWithAuth( |
| 7008 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7009 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7010 | |
| 7011 | rv = callback2.WaitForResult(); |
| 7012 | EXPECT_EQ(OK, rv); |
| 7013 | |
| 7014 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7015 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7016 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 7017 | } |
| 7018 | |
| 7019 | // ------------------------------------------------------------------------ |
| 7020 | |
| 7021 | // Transaction 2: Request another resource in digestive's protection space. |
| 7022 | // This will preemptively add an Authorization header which should have an |
| 7023 | // "nc" value of 2 (as compared to 1 in the first use. |
| 7024 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7025 | HttpRequestInfo request; |
| 7026 | request.method = "GET"; |
| 7027 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7028 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7029 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7030 | request.load_flags = 0; |
| 7031 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7032 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7033 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7034 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7035 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7036 | MockWrite( |
| 7037 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7038 | "Host: www.example.org\r\n" |
| 7039 | "Connection: keep-alive\r\n" |
| 7040 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 7041 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 7042 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 7043 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7044 | }; |
| 7045 | |
| 7046 | // Sever accepts the authorization. |
| 7047 | MockRead data_reads1[] = { |
| 7048 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7049 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7050 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7051 | }; |
| 7052 | |
| 7053 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7054 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7055 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7056 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7057 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7058 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7059 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7060 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7061 | |
| 7062 | rv = callback1.WaitForResult(); |
| 7063 | EXPECT_EQ(OK, rv); |
| 7064 | |
| 7065 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7066 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7067 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 7068 | } |
| 7069 | } |
| 7070 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7071 | // Test the ResetStateForRestart() private method. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7072 | TEST_P(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7073 | // Create a transaction (the dependencies aren't important). |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7074 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 7075 | scoped_ptr<HttpNetworkTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7076 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7077 | |
| 7078 | // Setup some state (which we expect ResetStateForRestart() will clear). |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7079 | trans->read_buf_ = new IOBuffer(15); |
| 7080 | trans->read_buf_len_ = 15; |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 7081 | trans->request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7082 | |
| 7083 | // Setup state in response_ |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 7084 | HttpResponseInfo* response = &trans->response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7085 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7086 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7087 | response->response_time = base::Time::Now(); |
| 7088 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7089 | |
| 7090 | { // Setup state for response_.vary_data |
| 7091 | HttpRequestInfo request; |
| 7092 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 7093 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 7094 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7095 | request.extra_headers.SetHeader("Foo", "1"); |
| 7096 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7097 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7098 | } |
| 7099 | |
| 7100 | // Cause the above state to be reset. |
| 7101 | trans->ResetStateForRestart(); |
| 7102 | |
| 7103 | // Verify that the state that needed to be reset, has been reset. |
[email protected] | 9b6fee1 | 2009-09-29 18:13:07 | [diff] [blame] | 7104 | EXPECT_TRUE(trans->read_buf_.get() == NULL); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7105 | EXPECT_EQ(0, trans->read_buf_len_); |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 7106 | EXPECT_TRUE(trans->request_headers_.IsEmpty()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7107 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 7108 | EXPECT_TRUE(response->headers.get() == NULL); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 7109 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7110 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7111 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7112 | } |
| 7113 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7114 | // Test HTTPS connections to a site with a bad certificate |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7115 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7116 | HttpRequestInfo request; |
| 7117 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7118 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7119 | request.load_flags = 0; |
| 7120 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7121 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7122 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7123 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7124 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7125 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7126 | MockWrite( |
| 7127 | "GET / HTTP/1.1\r\n" |
| 7128 | "Host: www.example.org\r\n" |
| 7129 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7130 | }; |
| 7131 | |
| 7132 | MockRead data_reads[] = { |
| 7133 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7134 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7135 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7136 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7137 | }; |
| 7138 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 7139 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7140 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7141 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7142 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7143 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7144 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7145 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7146 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7147 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7148 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7149 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7150 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7151 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7152 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7153 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7154 | |
| 7155 | rv = callback.WaitForResult(); |
| 7156 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 7157 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7158 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7159 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7160 | |
| 7161 | rv = callback.WaitForResult(); |
| 7162 | EXPECT_EQ(OK, rv); |
| 7163 | |
| 7164 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7165 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7166 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7167 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7168 | } |
| 7169 | |
| 7170 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 7171 | // proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7172 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7173 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7174 | |
| 7175 | HttpRequestInfo request; |
| 7176 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7177 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7178 | request.load_flags = 0; |
| 7179 | |
| 7180 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7181 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7182 | "Host: www.example.org:443\r\n" |
| 7183 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7184 | }; |
| 7185 | |
| 7186 | MockRead proxy_reads[] = { |
| 7187 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7188 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7189 | }; |
| 7190 | |
| 7191 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7192 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7193 | "Host: www.example.org:443\r\n" |
| 7194 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7195 | MockWrite("GET / HTTP/1.1\r\n" |
| 7196 | "Host: www.example.org\r\n" |
| 7197 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7198 | }; |
| 7199 | |
| 7200 | MockRead data_reads[] = { |
| 7201 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7202 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7203 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7204 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7205 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7206 | }; |
| 7207 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7208 | StaticSocketDataProvider ssl_bad_certificate( |
| 7209 | proxy_reads, arraysize(proxy_reads), |
| 7210 | proxy_writes, arraysize(proxy_writes)); |
| 7211 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7212 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7213 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7214 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7215 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7216 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7217 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7218 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7219 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7220 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7221 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7222 | |
| 7223 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7224 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7225 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7226 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 7227 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7228 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7229 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7230 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7231 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7232 | |
| 7233 | rv = callback.WaitForResult(); |
| 7234 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 7235 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7236 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7237 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7238 | |
| 7239 | rv = callback.WaitForResult(); |
| 7240 | EXPECT_EQ(OK, rv); |
| 7241 | |
| 7242 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7243 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7244 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7245 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7246 | } |
| 7247 | } |
| 7248 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7249 | |
| 7250 | // Test HTTPS connections to a site, going through an HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7251 | TEST_P(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7252 | session_deps_.proxy_service = |
| 7253 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7254 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7255 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7256 | |
| 7257 | HttpRequestInfo request; |
| 7258 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7259 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7260 | request.load_flags = 0; |
| 7261 | |
| 7262 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7263 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7264 | "Host: www.example.org:443\r\n" |
| 7265 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7266 | MockWrite("GET / HTTP/1.1\r\n" |
| 7267 | "Host: www.example.org\r\n" |
| 7268 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7269 | }; |
| 7270 | |
| 7271 | MockRead data_reads[] = { |
| 7272 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7273 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7274 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7275 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7276 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7277 | }; |
| 7278 | |
| 7279 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7280 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7281 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 7282 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7283 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7284 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7285 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 7286 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7287 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7288 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7289 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7290 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7291 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7292 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7293 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7294 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7295 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7296 | |
| 7297 | rv = callback.WaitForResult(); |
| 7298 | EXPECT_EQ(OK, rv); |
| 7299 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7300 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7301 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7302 | |
| 7303 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7304 | EXPECT_EQ(200, response->headers->response_code()); |
| 7305 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7306 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7307 | |
| 7308 | LoadTimingInfo load_timing_info; |
| 7309 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7310 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7311 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7312 | } |
| 7313 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7314 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7315 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7316 | session_deps_.proxy_service = |
| 7317 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7318 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7319 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7320 | |
| 7321 | HttpRequestInfo request; |
| 7322 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7323 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7324 | request.load_flags = 0; |
| 7325 | |
| 7326 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7327 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7328 | "Host: www.example.org:443\r\n" |
| 7329 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7330 | }; |
| 7331 | |
| 7332 | MockRead data_reads[] = { |
| 7333 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 7334 | MockRead("Location: http://login.example.com/\r\n"), |
| 7335 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7336 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7337 | }; |
| 7338 | |
| 7339 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7340 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7341 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7342 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7343 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7344 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7345 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7346 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7347 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7348 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7349 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7350 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7351 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7352 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7353 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7354 | |
| 7355 | rv = callback.WaitForResult(); |
| 7356 | EXPECT_EQ(OK, rv); |
| 7357 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7358 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7359 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7360 | |
| 7361 | EXPECT_EQ(302, response->headers->response_code()); |
| 7362 | std::string url; |
| 7363 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7364 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7365 | |
| 7366 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 7367 | // timing for the proxy connection instead of the connection to the host, |
| 7368 | // and no send / receive times. |
| 7369 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 7370 | LoadTimingInfo load_timing_info; |
| 7371 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7372 | |
| 7373 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 7374 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7375 | |
| 7376 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 7377 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 7378 | load_timing_info.proxy_resolve_end); |
| 7379 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 7380 | load_timing_info.connect_timing.connect_start); |
| 7381 | ExpectConnectTimingHasTimes( |
| 7382 | load_timing_info.connect_timing, |
| 7383 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7384 | |
| 7385 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 7386 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 7387 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7388 | } |
| 7389 | |
| 7390 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7391 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7392 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7393 | |
| 7394 | HttpRequestInfo request; |
| 7395 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7396 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7397 | request.load_flags = 0; |
| 7398 | |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 7399 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7400 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7401 | scoped_ptr<SpdyFrame> goaway( |
| 7402 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7403 | MockWrite data_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7404 | CreateMockWrite(*conn.get(), 0, SYNCHRONOUS), |
| 7405 | CreateMockWrite(*goaway.get(), 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7406 | }; |
| 7407 | |
| 7408 | static const char* const kExtraHeaders[] = { |
| 7409 | "location", |
| 7410 | "http://login.example.com/", |
| 7411 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7412 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7413 | spdy_util_.ConstructSpdySynReplyError("302 Redirect", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7414 | arraysize(kExtraHeaders)/2, 1)); |
| 7415 | MockRead data_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7416 | CreateMockRead(*resp.get(), 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7417 | }; |
| 7418 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7419 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7420 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7421 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7422 | proxy_ssl.SetNextProto(GetProtocol()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7423 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7424 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7425 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7426 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7427 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7428 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7429 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7430 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7431 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7432 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7433 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7434 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7435 | |
| 7436 | rv = callback.WaitForResult(); |
| 7437 | EXPECT_EQ(OK, rv); |
| 7438 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7439 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7440 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7441 | |
| 7442 | EXPECT_EQ(302, response->headers->response_code()); |
| 7443 | std::string url; |
| 7444 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7445 | EXPECT_EQ("http://login.example.com/", url); |
| 7446 | } |
| 7447 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7448 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7449 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7450 | ErrorResponseToHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7451 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7452 | |
| 7453 | HttpRequestInfo request; |
| 7454 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7455 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7456 | request.load_flags = 0; |
| 7457 | |
| 7458 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7459 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7460 | "Host: www.example.org:443\r\n" |
| 7461 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7462 | }; |
| 7463 | |
| 7464 | MockRead data_reads[] = { |
| 7465 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 7466 | MockRead("Content-Length: 23\r\n\r\n"), |
| 7467 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7468 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7469 | }; |
| 7470 | |
| 7471 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7472 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7473 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7474 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7475 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7476 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7477 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7478 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7479 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7480 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7481 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7482 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7483 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7484 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7485 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7486 | |
| 7487 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7488 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7489 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7490 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7491 | } |
| 7492 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7493 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7494 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7495 | ErrorResponseToHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7496 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7497 | |
| 7498 | HttpRequestInfo request; |
| 7499 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7500 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7501 | request.load_flags = 0; |
| 7502 | |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 7503 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7504 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7505 | scoped_ptr<SpdyFrame> rst( |
| 7506 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7507 | MockWrite data_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7508 | CreateMockWrite(*conn.get(), 0), CreateMockWrite(*rst.get(), 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7509 | }; |
| 7510 | |
| 7511 | static const char* const kExtraHeaders[] = { |
| 7512 | "location", |
| 7513 | "http://login.example.com/", |
| 7514 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7515 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7516 | spdy_util_.ConstructSpdySynReplyError("404 Not Found", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7517 | arraysize(kExtraHeaders)/2, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7518 | scoped_ptr<SpdyFrame> body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7519 | spdy_util_.ConstructSpdyBodyFrame( |
| 7520 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7521 | MockRead data_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7522 | CreateMockRead(*resp.get(), 1), |
| 7523 | CreateMockRead(*body.get(), 2), |
| 7524 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7525 | }; |
| 7526 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7527 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7528 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7529 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7530 | proxy_ssl.SetNextProto(GetProtocol()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7531 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7532 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7533 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7534 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7535 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7536 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7537 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7538 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7539 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7540 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7541 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7542 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7543 | |
| 7544 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7545 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7546 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7547 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7548 | } |
| 7549 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7550 | // Test the request-challenge-retry sequence for basic auth, through |
| 7551 | // a SPDY proxy over a single SPDY session. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7552 | TEST_P(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7553 | HttpRequestInfo request; |
| 7554 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7555 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7556 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 7557 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7558 | |
| 7559 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7560 | session_deps_.proxy_service = |
| 7561 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7562 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7563 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7564 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7565 | |
| 7566 | // Since we have proxy, should try to establish tunnel. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 7567 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7568 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7569 | scoped_ptr<SpdyFrame> rst( |
| 7570 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7571 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7572 | |
| 7573 | // After calling trans->RestartWithAuth(), this is the request we should |
| 7574 | // be issuing -- the final header line contains the credentials. |
| 7575 | const char* const kAuthCredentials[] = { |
| 7576 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 7577 | }; |
[email protected] | fba2dbde | 2013-05-24 16:09:01 | [diff] [blame] | 7578 | scoped_ptr<SpdyFrame> connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 7579 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7580 | HostPortPair("www.example.org", 443))); |
| 7581 | // fetch https://www.example.org/ via HTTP |
| 7582 | const char get[] = |
| 7583 | "GET / HTTP/1.1\r\n" |
| 7584 | "Host: www.example.org\r\n" |
| 7585 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7586 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7587 | spdy_util_.ConstructSpdyBodyFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7588 | |
| 7589 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7590 | CreateMockWrite(*req, 0, ASYNC), |
| 7591 | CreateMockWrite(*rst, 2, ASYNC), |
| 7592 | CreateMockWrite(*connect2, 3), |
| 7593 | CreateMockWrite(*wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7594 | }; |
| 7595 | |
| 7596 | // The proxy responds to the connect with a 407, using a persistent |
| 7597 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 7598 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7599 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7600 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 7601 | }; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 7602 | scoped_ptr<SpdyFrame> conn_auth_resp(spdy_util_.ConstructSpdySynReplyError( |
| 7603 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7604 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7605 | scoped_ptr<SpdyFrame> conn_resp( |
| 7606 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7607 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 7608 | "Content-Length: 5\r\n\r\n"; |
| 7609 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7610 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7611 | spdy_util_.ConstructSpdyBodyFrame(3, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7612 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7613 | spdy_util_.ConstructSpdyBodyFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7614 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7615 | CreateMockRead(*conn_auth_resp, 1, ASYNC), |
| 7616 | CreateMockRead(*conn_resp, 4, ASYNC), |
| 7617 | CreateMockRead(*wrapped_get_resp, 6, ASYNC), |
| 7618 | CreateMockRead(*wrapped_body, 7, ASYNC), |
| 7619 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7620 | }; |
| 7621 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7622 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7623 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7624 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7625 | // Negotiate SPDY to the proxy |
| 7626 | SSLSocketDataProvider proxy(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7627 | proxy.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7628 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7629 | // Vanilla SSL to the server |
| 7630 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7631 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7632 | |
| 7633 | TestCompletionCallback callback1; |
| 7634 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7635 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7636 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7637 | |
| 7638 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 7639 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7640 | |
| 7641 | rv = callback1.WaitForResult(); |
| 7642 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 7643 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7644 | log.GetEntries(&entries); |
| 7645 | size_t pos = ExpectLogContainsSomewhere( |
| 7646 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 7647 | NetLog::PHASE_NONE); |
| 7648 | ExpectLogContainsSomewhere( |
| 7649 | entries, pos, |
| 7650 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 7651 | NetLog::PHASE_NONE); |
| 7652 | |
| 7653 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7654 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7655 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7656 | EXPECT_EQ(407, response->headers->response_code()); |
| 7657 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7658 | EXPECT_TRUE(response->auth_challenge.get() != NULL); |
| 7659 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 7660 | |
| 7661 | TestCompletionCallback callback2; |
| 7662 | |
| 7663 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7664 | callback2.callback()); |
| 7665 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7666 | |
| 7667 | rv = callback2.WaitForResult(); |
| 7668 | EXPECT_EQ(OK, rv); |
| 7669 | |
| 7670 | response = trans->GetResponseInfo(); |
| 7671 | ASSERT_TRUE(response != NULL); |
| 7672 | |
| 7673 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7674 | EXPECT_EQ(200, response->headers->response_code()); |
| 7675 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 7676 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7677 | |
| 7678 | // The password prompt info should not be set. |
| 7679 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 7680 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7681 | LoadTimingInfo load_timing_info; |
| 7682 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7683 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7684 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7685 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7686 | trans.reset(); |
| 7687 | session->CloseAllConnections(); |
| 7688 | } |
| 7689 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7690 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 7691 | // origin that is different from that of its associated resource. |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 7692 | TEST_P(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
| 7693 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
| 7694 | scoped_ptr<TestProxyDelegate> proxy_delegate(new TestProxyDelegate()); |
| 7695 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 7696 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7697 | HttpRequestInfo request; |
| 7698 | HttpRequestInfo push_request; |
| 7699 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7700 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7701 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7702 | push_request.method = "GET"; |
| 7703 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 7704 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 7705 | // Configure against https proxy server "myproxy:443". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7706 | session_deps_.proxy_service = |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 7707 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7708 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7709 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7710 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 7711 | session_deps_.proxy_delegate.reset(proxy_delegate.release()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7712 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7713 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7714 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 7715 | scoped_ptr<SpdyFrame> stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 7716 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, false)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7717 | |
| 7718 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7719 | CreateMockWrite(*stream1_syn, 0, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7720 | }; |
| 7721 | |
| 7722 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7723 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7724 | |
| 7725 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7726 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7727 | |
| 7728 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7729 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7730 | 0, |
| 7731 | 2, |
| 7732 | 1, |
| 7733 | "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7734 | const char kPushedData[] = "pushed"; |
| 7735 | scoped_ptr<SpdyFrame> stream2_body( |
| 7736 | spdy_util_.ConstructSpdyBodyFrame( |
| 7737 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7738 | |
| 7739 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7740 | CreateMockRead(*stream1_reply, 1, ASYNC), |
| 7741 | CreateMockRead(*stream2_syn, 2, ASYNC), |
| 7742 | CreateMockRead(*stream1_body, 3, ASYNC), |
| 7743 | CreateMockRead(*stream2_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 7744 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7745 | }; |
| 7746 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7747 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7748 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7749 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7750 | // Negotiate SPDY to the proxy |
| 7751 | SSLSocketDataProvider proxy(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7752 | proxy.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7753 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7754 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7755 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7756 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7757 | TestCompletionCallback callback; |
| 7758 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 7759 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7760 | |
| 7761 | rv = callback.WaitForResult(); |
| 7762 | EXPECT_EQ(OK, rv); |
| 7763 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7764 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7765 | scoped_ptr<HttpTransaction> push_trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7766 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 7767 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7768 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7769 | |
| 7770 | rv = callback.WaitForResult(); |
| 7771 | EXPECT_EQ(OK, rv); |
| 7772 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 7773 | |
| 7774 | ASSERT_TRUE(response != NULL); |
| 7775 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7776 | |
| 7777 | EXPECT_EQ(200, response->headers->response_code()); |
| 7778 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7779 | |
| 7780 | std::string response_data; |
| 7781 | rv = ReadTransaction(trans.get(), &response_data); |
| 7782 | EXPECT_EQ(OK, rv); |
| 7783 | EXPECT_EQ("hello!", response_data); |
| 7784 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7785 | LoadTimingInfo load_timing_info; |
| 7786 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7787 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7788 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7789 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7790 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7791 | EXPECT_TRUE(push_response->headers.get() != NULL); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7792 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 7793 | |
| 7794 | rv = ReadTransaction(push_trans.get(), &response_data); |
| 7795 | EXPECT_EQ(OK, rv); |
| 7796 | EXPECT_EQ("pushed", response_data); |
| 7797 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7798 | LoadTimingInfo push_load_timing_info; |
| 7799 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 7800 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 7801 | // The transactions should share a socket ID, despite being for different |
| 7802 | // origins. |
| 7803 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 7804 | push_load_timing_info.socket_log_id); |
| 7805 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7806 | trans.reset(); |
| 7807 | push_trans.reset(); |
| 7808 | session->CloseAllConnections(); |
| 7809 | } |
| 7810 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7811 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7812 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 7813 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
| 7814 | scoped_ptr<TestProxyDelegate> proxy_delegate(new TestProxyDelegate()); |
| 7815 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 7816 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7817 | HttpRequestInfo request; |
| 7818 | |
| 7819 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7820 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7821 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 7822 | session_deps_.proxy_service = |
| 7823 | ProxyService::CreateFixed("https://myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7824 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7825 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7826 | |
| 7827 | // Enable cross-origin push. |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 7828 | session_deps_.proxy_delegate.reset(proxy_delegate.release()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7829 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7830 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7831 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 7832 | scoped_ptr<SpdyFrame> stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 7833 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, false)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7834 | |
| 7835 | scoped_ptr<SpdyFrame> push_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7836 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7837 | |
| 7838 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7839 | CreateMockWrite(*stream1_syn, 0, ASYNC), CreateMockWrite(*push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7840 | }; |
| 7841 | |
| 7842 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7843 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7844 | |
| 7845 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7846 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7847 | |
| 7848 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7849 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7850 | 0, |
| 7851 | 2, |
| 7852 | 1, |
| 7853 | "https://www.another-origin.com/foo.dat")); |
| 7854 | |
| 7855 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7856 | CreateMockRead(*stream1_reply, 1, ASYNC), |
| 7857 | CreateMockRead(*stream2_syn, 2, ASYNC), |
| 7858 | CreateMockRead(*stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 7859 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7860 | }; |
| 7861 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7862 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7863 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7864 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7865 | // Negotiate SPDY to the proxy |
| 7866 | SSLSocketDataProvider proxy(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7867 | proxy.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7868 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7869 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7870 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7871 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7872 | TestCompletionCallback callback; |
| 7873 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 7874 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7875 | |
| 7876 | rv = callback.WaitForResult(); |
| 7877 | EXPECT_EQ(OK, rv); |
| 7878 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7879 | |
| 7880 | ASSERT_TRUE(response != NULL); |
| 7881 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7882 | |
| 7883 | EXPECT_EQ(200, response->headers->response_code()); |
| 7884 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7885 | |
| 7886 | std::string response_data; |
| 7887 | rv = ReadTransaction(trans.get(), &response_data); |
| 7888 | EXPECT_EQ(OK, rv); |
| 7889 | EXPECT_EQ("hello!", response_data); |
| 7890 | |
| 7891 | trans.reset(); |
| 7892 | session->CloseAllConnections(); |
| 7893 | } |
| 7894 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 7895 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 7896 | // resources. |
| 7897 | TEST_P(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 7898 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
| 7899 | scoped_ptr<TestProxyDelegate> proxy_delegate(new TestProxyDelegate()); |
| 7900 | proxy_delegate->set_trusted_spdy_proxy( |
| 7901 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 7902 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 7903 | HttpRequestInfo request; |
| 7904 | |
| 7905 | request.method = "GET"; |
| 7906 | request.url = GURL("http://www.example.org/"); |
| 7907 | |
| 7908 | // Configure against https proxy server "myproxy:70". |
| 7909 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
| 7910 | BoundTestNetLog log; |
| 7911 | session_deps_.net_log = log.bound().net_log(); |
| 7912 | |
| 7913 | // Enable cross-origin push. |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 7914 | session_deps_.proxy_delegate.reset(proxy_delegate.release()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 7915 | |
| 7916 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7917 | |
| 7918 | scoped_ptr<SpdyFrame> stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 7919 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, false)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 7920 | |
| 7921 | MockWrite spdy_writes[] = { |
| 7922 | CreateMockWrite(*stream1_syn, 0, ASYNC), |
| 7923 | }; |
| 7924 | |
| 7925 | scoped_ptr<SpdyFrame> stream1_reply( |
| 7926 | spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
| 7927 | |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 7928 | scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 7929 | nullptr, 0, 2, 1, "https://myproxy:70/foo.dat")); |
| 7930 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 7931 | scoped_ptr<SpdyFrame> stream1_body( |
| 7932 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 7933 | |
| 7934 | scoped_ptr<SpdyFrame> stream2_reply( |
| 7935 | spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
| 7936 | |
| 7937 | scoped_ptr<SpdyFrame> stream2_body( |
| 7938 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 7939 | |
| 7940 | MockRead spdy_reads[] = { |
| 7941 | CreateMockRead(*stream1_reply, 1, ASYNC), |
| 7942 | CreateMockRead(*stream2_syn, 2, ASYNC), |
| 7943 | CreateMockRead(*stream1_body, 3, ASYNC), |
| 7944 | CreateMockRead(*stream2_body, 4, ASYNC), |
| 7945 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
| 7946 | }; |
| 7947 | |
| 7948 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7949 | arraysize(spdy_writes)); |
| 7950 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 7951 | // Negotiate SPDY to the proxy |
| 7952 | SSLSocketDataProvider proxy(ASYNC, OK); |
| 7953 | proxy.SetNextProto(GetProtocol()); |
| 7954 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 7955 | |
| 7956 | scoped_ptr<HttpTransaction> trans( |
| 7957 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 7958 | TestCompletionCallback callback; |
| 7959 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 7960 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7961 | |
| 7962 | rv = callback.WaitForResult(); |
| 7963 | EXPECT_EQ(OK, rv); |
| 7964 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7965 | |
| 7966 | ASSERT_TRUE(response != nullptr); |
| 7967 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7968 | |
| 7969 | EXPECT_EQ(200, response->headers->response_code()); |
| 7970 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7971 | |
| 7972 | std::string response_data; |
| 7973 | rv = ReadTransaction(trans.get(), &response_data); |
| 7974 | EXPECT_EQ(OK, rv); |
| 7975 | EXPECT_EQ("hello!", response_data); |
| 7976 | |
| 7977 | trans.reset(); |
| 7978 | session->CloseAllConnections(); |
| 7979 | } |
| 7980 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7981 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 7982 | // HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7983 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7984 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7985 | |
| 7986 | HttpRequestInfo request; |
| 7987 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7988 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7989 | request.load_flags = 0; |
| 7990 | |
| 7991 | // Attempt to fetch the URL from a server with a bad cert |
| 7992 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7993 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7994 | "Host: www.example.org:443\r\n" |
| 7995 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7996 | }; |
| 7997 | |
| 7998 | MockRead bad_cert_reads[] = { |
| 7999 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8000 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8001 | }; |
| 8002 | |
| 8003 | // Attempt to fetch the URL with a good cert |
| 8004 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8005 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8006 | "Host: www.example.org:443\r\n" |
| 8007 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8008 | MockWrite("GET / HTTP/1.1\r\n" |
| 8009 | "Host: www.example.org\r\n" |
| 8010 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8011 | }; |
| 8012 | |
| 8013 | MockRead good_cert_reads[] = { |
| 8014 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8015 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8016 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8017 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8018 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8019 | }; |
| 8020 | |
| 8021 | StaticSocketDataProvider ssl_bad_certificate( |
| 8022 | bad_cert_reads, arraysize(bad_cert_reads), |
| 8023 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 8024 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 8025 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8026 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8027 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8028 | |
| 8029 | // SSL to the proxy, then CONNECT request, then SSL with bad 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(&ssl_bad_certificate); |
| 8032 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8033 | |
| 8034 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8035 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8036 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8037 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8038 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8039 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8040 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8041 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8042 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8043 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8044 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8045 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8046 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8047 | |
| 8048 | rv = callback.WaitForResult(); |
| 8049 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 8050 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8051 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8052 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8053 | |
| 8054 | rv = callback.WaitForResult(); |
| 8055 | EXPECT_EQ(OK, rv); |
| 8056 | |
| 8057 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8058 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8059 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8060 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8061 | } |
| 8062 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8063 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8064 | HttpRequestInfo request; |
| 8065 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8066 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8067 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8068 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8069 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8070 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8071 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8072 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8073 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8074 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8075 | MockWrite( |
| 8076 | "GET / HTTP/1.1\r\n" |
| 8077 | "Host: www.example.org\r\n" |
| 8078 | "Connection: keep-alive\r\n" |
| 8079 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8080 | }; |
| 8081 | |
| 8082 | // Lastly, the server responds with the actual content. |
| 8083 | MockRead data_reads[] = { |
| 8084 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8085 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8086 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8087 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8088 | }; |
| 8089 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8090 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8091 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8092 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8093 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8094 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8095 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8096 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8097 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8098 | |
| 8099 | rv = callback.WaitForResult(); |
| 8100 | EXPECT_EQ(OK, rv); |
| 8101 | } |
| 8102 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8103 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8104 | HttpRequestInfo request; |
| 8105 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8106 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8107 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8108 | "Chromium Ultra Awesome X Edition"); |
| 8109 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8110 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8111 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8112 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8113 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8114 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8115 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8116 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8117 | "Host: www.example.org:443\r\n" |
| 8118 | "Proxy-Connection: keep-alive\r\n" |
| 8119 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8120 | }; |
| 8121 | MockRead data_reads[] = { |
| 8122 | // Return an error, so the transaction stops here (this test isn't |
| 8123 | // interested in the rest). |
| 8124 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 8125 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8126 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 8127 | }; |
| 8128 | |
| 8129 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8130 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8131 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8132 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8133 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8134 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8135 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8136 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8137 | |
| 8138 | rv = callback.WaitForResult(); |
| 8139 | EXPECT_EQ(OK, rv); |
| 8140 | } |
| 8141 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8142 | TEST_P(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8143 | HttpRequestInfo request; |
| 8144 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8145 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8146 | request.load_flags = 0; |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 8147 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 8148 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8149 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8150 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8151 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8152 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8153 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8154 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8155 | MockWrite( |
| 8156 | "GET / HTTP/1.1\r\n" |
| 8157 | "Host: www.example.org\r\n" |
| 8158 | "Connection: keep-alive\r\n" |
| 8159 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8160 | }; |
| 8161 | |
| 8162 | // Lastly, the server responds with the actual content. |
| 8163 | MockRead data_reads[] = { |
| 8164 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8165 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8166 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8167 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8168 | }; |
| 8169 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8170 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8171 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8172 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8173 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8174 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8175 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8176 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8177 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8178 | |
| 8179 | rv = callback.WaitForResult(); |
| 8180 | EXPECT_EQ(OK, rv); |
| 8181 | } |
| 8182 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8183 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8184 | HttpRequestInfo request; |
| 8185 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8186 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8187 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8188 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8189 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8190 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8191 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8192 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8193 | MockWrite( |
| 8194 | "POST / HTTP/1.1\r\n" |
| 8195 | "Host: www.example.org\r\n" |
| 8196 | "Connection: keep-alive\r\n" |
| 8197 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8198 | }; |
| 8199 | |
| 8200 | // Lastly, the server responds with the actual content. |
| 8201 | MockRead data_reads[] = { |
| 8202 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8203 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8204 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8205 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8206 | }; |
| 8207 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8208 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8209 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8210 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8211 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8212 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8213 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8214 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8215 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8216 | |
| 8217 | rv = callback.WaitForResult(); |
| 8218 | EXPECT_EQ(OK, rv); |
| 8219 | } |
| 8220 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8221 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8222 | HttpRequestInfo request; |
| 8223 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8224 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8225 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8226 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8227 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8228 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8229 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8230 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8231 | MockWrite( |
| 8232 | "PUT / HTTP/1.1\r\n" |
| 8233 | "Host: www.example.org\r\n" |
| 8234 | "Connection: keep-alive\r\n" |
| 8235 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8236 | }; |
| 8237 | |
| 8238 | // Lastly, the server responds with the actual content. |
| 8239 | MockRead data_reads[] = { |
| 8240 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8241 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8242 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8243 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8244 | }; |
| 8245 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8246 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8247 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8248 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8249 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8250 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8251 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8252 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8253 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8254 | |
| 8255 | rv = callback.WaitForResult(); |
| 8256 | EXPECT_EQ(OK, rv); |
| 8257 | } |
| 8258 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8259 | TEST_P(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8260 | HttpRequestInfo request; |
| 8261 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8262 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8263 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8264 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8265 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8266 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8267 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8268 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 8269 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 8270 | "Host: www.example.org\r\n" |
| 8271 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8272 | }; |
| 8273 | |
| 8274 | // Lastly, the server responds with the actual content. |
| 8275 | MockRead data_reads[] = { |
| 8276 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8277 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8278 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8279 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8280 | }; |
| 8281 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8282 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8283 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8284 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8285 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8286 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8287 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8288 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8289 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8290 | |
| 8291 | rv = callback.WaitForResult(); |
| 8292 | EXPECT_EQ(OK, rv); |
| 8293 | } |
| 8294 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8295 | TEST_P(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8296 | HttpRequestInfo request; |
| 8297 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8298 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8299 | request.load_flags = LOAD_BYPASS_CACHE; |
| 8300 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8301 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8302 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8303 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8304 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8305 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8306 | MockWrite( |
| 8307 | "GET / HTTP/1.1\r\n" |
| 8308 | "Host: www.example.org\r\n" |
| 8309 | "Connection: keep-alive\r\n" |
| 8310 | "Pragma: no-cache\r\n" |
| 8311 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8312 | }; |
| 8313 | |
| 8314 | // Lastly, the server responds with the actual content. |
| 8315 | MockRead data_reads[] = { |
| 8316 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8317 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8318 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8319 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8320 | }; |
| 8321 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8322 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8323 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8324 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8325 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8326 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8327 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8328 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8329 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8330 | |
| 8331 | rv = callback.WaitForResult(); |
| 8332 | EXPECT_EQ(OK, rv); |
| 8333 | } |
| 8334 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8335 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8336 | BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8337 | HttpRequestInfo request; |
| 8338 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8339 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8340 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 8341 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8342 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8343 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8344 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8345 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8346 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8347 | MockWrite( |
| 8348 | "GET / HTTP/1.1\r\n" |
| 8349 | "Host: www.example.org\r\n" |
| 8350 | "Connection: keep-alive\r\n" |
| 8351 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8352 | }; |
| 8353 | |
| 8354 | // Lastly, the server responds with the actual content. |
| 8355 | MockRead data_reads[] = { |
| 8356 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8357 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8358 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8359 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8360 | }; |
| 8361 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8362 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8363 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8364 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8365 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8366 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8367 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8368 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8369 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8370 | |
| 8371 | rv = callback.WaitForResult(); |
| 8372 | EXPECT_EQ(OK, rv); |
| 8373 | } |
| 8374 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8375 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8376 | HttpRequestInfo request; |
| 8377 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8378 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8379 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8380 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8381 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8382 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8383 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8384 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8385 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8386 | MockWrite( |
| 8387 | "GET / HTTP/1.1\r\n" |
| 8388 | "Host: www.example.org\r\n" |
| 8389 | "Connection: keep-alive\r\n" |
| 8390 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8391 | }; |
| 8392 | |
| 8393 | // Lastly, the server responds with the actual content. |
| 8394 | MockRead data_reads[] = { |
| 8395 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8396 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8397 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8398 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8399 | }; |
| 8400 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8401 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8402 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8403 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8404 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8405 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8406 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8407 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8408 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8409 | |
| 8410 | rv = callback.WaitForResult(); |
| 8411 | EXPECT_EQ(OK, rv); |
| 8412 | } |
| 8413 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8414 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8415 | HttpRequestInfo request; |
| 8416 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8417 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8418 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 8419 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 8420 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8421 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8422 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8423 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8424 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8425 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8426 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8427 | MockWrite( |
| 8428 | "GET / HTTP/1.1\r\n" |
| 8429 | "Host: www.example.org\r\n" |
| 8430 | "Connection: keep-alive\r\n" |
| 8431 | "referer: www.foo.com\r\n" |
| 8432 | "hEllo: Kitty\r\n" |
| 8433 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8434 | }; |
| 8435 | |
| 8436 | // Lastly, the server responds with the actual content. |
| 8437 | MockRead data_reads[] = { |
| 8438 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8439 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8440 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8441 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8442 | }; |
| 8443 | |
| 8444 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8445 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8446 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8447 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8448 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8449 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8450 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8451 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8452 | |
| 8453 | rv = callback.WaitForResult(); |
| 8454 | EXPECT_EQ(OK, rv); |
| 8455 | } |
| 8456 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8457 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8458 | HttpRequestInfo request; |
| 8459 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8460 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8461 | request.load_flags = 0; |
| 8462 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8463 | session_deps_.proxy_service = |
| 8464 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8465 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8466 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8467 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8468 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8469 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8470 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8471 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8472 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 8473 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8474 | |
| 8475 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8476 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 8477 | MockWrite( |
| 8478 | "GET / HTTP/1.1\r\n" |
| 8479 | "Host: www.example.org\r\n" |
| 8480 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8481 | |
| 8482 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8483 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8484 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8485 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8486 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8487 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8488 | }; |
| 8489 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8490 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8491 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8492 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8493 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8494 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8495 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8496 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8497 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8498 | |
| 8499 | rv = callback.WaitForResult(); |
| 8500 | EXPECT_EQ(OK, rv); |
| 8501 | |
| 8502 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8503 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8504 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8505 | LoadTimingInfo load_timing_info; |
| 8506 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8507 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8508 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8509 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8510 | std::string response_text; |
| 8511 | rv = ReadTransaction(trans.get(), &response_text); |
| 8512 | EXPECT_EQ(OK, rv); |
| 8513 | EXPECT_EQ("Payload", response_text); |
| 8514 | } |
| 8515 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8516 | TEST_P(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8517 | HttpRequestInfo request; |
| 8518 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8519 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8520 | request.load_flags = 0; |
| 8521 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8522 | session_deps_.proxy_service = |
| 8523 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8524 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8525 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8526 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8527 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8528 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8529 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8530 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8531 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 8532 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8533 | |
| 8534 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8535 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 8536 | arraysize(write_buffer)), |
| 8537 | MockWrite( |
| 8538 | "GET / HTTP/1.1\r\n" |
| 8539 | "Host: www.example.org\r\n" |
| 8540 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8541 | |
| 8542 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8543 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 8544 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8545 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8546 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8547 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8548 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8549 | }; |
| 8550 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8551 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8552 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8553 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8554 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8555 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8556 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8557 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8558 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8559 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8560 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8561 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8562 | |
| 8563 | rv = callback.WaitForResult(); |
| 8564 | EXPECT_EQ(OK, rv); |
| 8565 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8566 | LoadTimingInfo load_timing_info; |
| 8567 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8568 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8569 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8570 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8571 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8572 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8573 | |
| 8574 | std::string response_text; |
| 8575 | rv = ReadTransaction(trans.get(), &response_text); |
| 8576 | EXPECT_EQ(OK, rv); |
| 8577 | EXPECT_EQ("Payload", response_text); |
| 8578 | } |
| 8579 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8580 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8581 | HttpRequestInfo request; |
| 8582 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8583 | request.url = GURL("http://www.example.org/"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8584 | request.load_flags = 0; |
| 8585 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8586 | session_deps_.proxy_service = |
| 8587 | ProxyService::CreateFixed("socks4://myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8588 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8589 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8590 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8591 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8592 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8593 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8594 | |
| 8595 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 8596 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8597 | |
| 8598 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8599 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 8600 | MockWrite( |
| 8601 | "GET / HTTP/1.1\r\n" |
| 8602 | "Host: www.example.org\r\n" |
| 8603 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8604 | |
| 8605 | MockRead data_reads[] = { |
| 8606 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 8607 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8608 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8609 | MockRead("Payload"), |
| 8610 | MockRead(SYNCHRONOUS, OK) |
| 8611 | }; |
| 8612 | |
| 8613 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8614 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8615 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8616 | |
| 8617 | TestCompletionCallback callback; |
| 8618 | |
| 8619 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8620 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8621 | |
| 8622 | rv = callback.WaitForResult(); |
| 8623 | EXPECT_EQ(OK, rv); |
| 8624 | |
| 8625 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8626 | ASSERT_TRUE(response != NULL); |
| 8627 | |
| 8628 | LoadTimingInfo load_timing_info; |
| 8629 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8630 | TestLoadTimingNotReused(load_timing_info, |
| 8631 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8632 | |
| 8633 | std::string response_text; |
| 8634 | rv = ReadTransaction(trans.get(), &response_text); |
| 8635 | EXPECT_EQ(OK, rv); |
| 8636 | EXPECT_EQ("Payload", response_text); |
| 8637 | } |
| 8638 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8639 | TEST_P(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8640 | HttpRequestInfo request; |
| 8641 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8642 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8643 | request.load_flags = 0; |
| 8644 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8645 | session_deps_.proxy_service = |
| 8646 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8647 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8648 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8649 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8650 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8651 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8652 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8653 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8654 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 8655 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8656 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8657 | 0x05, // Version |
| 8658 | 0x01, // Command (CONNECT) |
| 8659 | 0x00, // Reserved. |
| 8660 | 0x03, // Address type (DOMAINNAME). |
| 8661 | 0x0F, // Length of domain (15) |
| 8662 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 8663 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8664 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8665 | const char kSOCKS5OkResponse[] = |
| 8666 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 8667 | |
| 8668 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8669 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 8670 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 8671 | MockWrite( |
| 8672 | "GET / HTTP/1.1\r\n" |
| 8673 | "Host: www.example.org\r\n" |
| 8674 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8675 | |
| 8676 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8677 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 8678 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8679 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8680 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8681 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8682 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8683 | }; |
| 8684 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8685 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8686 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8687 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8688 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8689 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8690 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8691 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8692 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8693 | |
| 8694 | rv = callback.WaitForResult(); |
| 8695 | EXPECT_EQ(OK, rv); |
| 8696 | |
| 8697 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8698 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8699 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8700 | LoadTimingInfo load_timing_info; |
| 8701 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8702 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8703 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8704 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8705 | std::string response_text; |
| 8706 | rv = ReadTransaction(trans.get(), &response_text); |
| 8707 | EXPECT_EQ(OK, rv); |
| 8708 | EXPECT_EQ("Payload", response_text); |
| 8709 | } |
| 8710 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8711 | TEST_P(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8712 | HttpRequestInfo request; |
| 8713 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8714 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8715 | request.load_flags = 0; |
| 8716 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8717 | session_deps_.proxy_service = |
| 8718 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8719 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8720 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8721 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8722 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8723 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8724 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8725 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8726 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 8727 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8728 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8729 | 0x05, // Version |
| 8730 | 0x01, // Command (CONNECT) |
| 8731 | 0x00, // Reserved. |
| 8732 | 0x03, // Address type (DOMAINNAME). |
| 8733 | 0x0F, // Length of domain (15) |
| 8734 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 8735 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8736 | }; |
| 8737 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8738 | const char kSOCKS5OkResponse[] = |
| 8739 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 8740 | |
| 8741 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8742 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 8743 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 8744 | arraysize(kSOCKS5OkRequest)), |
| 8745 | MockWrite( |
| 8746 | "GET / HTTP/1.1\r\n" |
| 8747 | "Host: www.example.org\r\n" |
| 8748 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8749 | |
| 8750 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8751 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 8752 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8753 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8754 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8755 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8756 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8757 | }; |
| 8758 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8759 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8760 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8761 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8762 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8763 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8764 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8765 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8766 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8767 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8768 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8769 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8770 | |
| 8771 | rv = callback.WaitForResult(); |
| 8772 | EXPECT_EQ(OK, rv); |
| 8773 | |
| 8774 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8775 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8776 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8777 | LoadTimingInfo load_timing_info; |
| 8778 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8779 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8780 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8781 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8782 | std::string response_text; |
| 8783 | rv = ReadTransaction(trans.get(), &response_text); |
| 8784 | EXPECT_EQ(OK, rv); |
| 8785 | EXPECT_EQ("Payload", response_text); |
| 8786 | } |
| 8787 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8788 | namespace { |
| 8789 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8790 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8791 | |
| 8792 | struct GroupNameTest { |
| 8793 | std::string proxy_server; |
| 8794 | std::string url; |
| 8795 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8796 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8797 | }; |
| 8798 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8799 | scoped_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8800 | NextProto next_proto, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8801 | SpdySessionDependencies* session_deps_) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8802 | scoped_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8803 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8804 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8805 | session->http_server_properties(); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 8806 | AlternativeService alternative_service( |
bnc | 4988e43 | 2015-03-31 03:06:25 | [diff] [blame] | 8807 | AlternateProtocolFromNextProto(next_proto), "", 443); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 8808 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 8809 | http_server_properties->SetAlternativeService( |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 8810 | HostPortPair("host.with.alternate", 80), alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8811 | |
| 8812 | return session; |
| 8813 | } |
| 8814 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8815 | int GroupNameTransactionHelper(const std::string& url, |
| 8816 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8817 | HttpRequestInfo request; |
| 8818 | request.method = "GET"; |
| 8819 | request.url = GURL(url); |
| 8820 | request.load_flags = 0; |
| 8821 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8822 | scoped_ptr<HttpTransaction> trans( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8823 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8824 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8825 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8826 | |
| 8827 | // We do not complete this request, the dtor will clean the transaction up. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8828 | return trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8829 | } |
| 8830 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8831 | } // namespace |
| 8832 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8833 | TEST_P(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8834 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8835 | { |
| 8836 | "", // unused |
| 8837 | "http://www.example.org/direct", |
| 8838 | "www.example.org:80", |
| 8839 | false, |
| 8840 | }, |
| 8841 | { |
| 8842 | "", // unused |
| 8843 | "http://[2001:1418:13:1::25]/direct", |
| 8844 | "[2001:1418:13:1::25]:80", |
| 8845 | false, |
| 8846 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8847 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8848 | // SSL Tests |
| 8849 | { |
| 8850 | "", // unused |
| 8851 | "https://www.example.org/direct_ssl", |
| 8852 | "ssl/www.example.org:443", |
| 8853 | true, |
| 8854 | }, |
| 8855 | { |
| 8856 | "", // unused |
| 8857 | "https://[2001:1418:13:1::25]/direct", |
| 8858 | "ssl/[2001:1418:13:1::25]:443", |
| 8859 | true, |
| 8860 | }, |
| 8861 | { |
| 8862 | "", // unused |
| 8863 | "http://host.with.alternate/direct", |
| 8864 | "ssl/host.with.alternate:443", |
| 8865 | true, |
| 8866 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8867 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8868 | |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 8869 | session_deps_.parse_alternative_services = true; |
| 8870 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8871 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8872 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8873 | session_deps_.proxy_service = |
| 8874 | ProxyService::CreateFixed(tests[i].proxy_server); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8875 | scoped_ptr<HttpNetworkSession> session( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8876 | SetupSessionForGroupNameTests(GetProtocol(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8877 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8878 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 8879 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
| 8880 | new CaptureGroupNameTransportSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8881 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8882 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8883 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8884 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8885 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 8886 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 8887 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8888 | |
| 8889 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8890 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8891 | if (tests[i].ssl) |
| 8892 | EXPECT_EQ(tests[i].expected_group_name, |
| 8893 | ssl_conn_pool->last_group_name_received()); |
| 8894 | else |
| 8895 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 8896 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8897 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8898 | } |
| 8899 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8900 | TEST_P(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8901 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8902 | { |
| 8903 | "http_proxy", |
| 8904 | "http://www.example.org/http_proxy_normal", |
| 8905 | "www.example.org:80", |
| 8906 | false, |
| 8907 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8908 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8909 | // SSL Tests |
| 8910 | { |
| 8911 | "http_proxy", |
| 8912 | "https://www.example.org/http_connect_ssl", |
| 8913 | "ssl/www.example.org:443", |
| 8914 | true, |
| 8915 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 8916 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8917 | { |
| 8918 | "http_proxy", |
| 8919 | "http://host.with.alternate/direct", |
| 8920 | "ssl/host.with.alternate:443", |
| 8921 | true, |
| 8922 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 8923 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8924 | { |
| 8925 | "http_proxy", |
| 8926 | "ftp://ftp.google.com/http_proxy_normal", |
| 8927 | "ftp/ftp.google.com:21", |
| 8928 | false, |
| 8929 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8930 | }; |
| 8931 | |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 8932 | session_deps_.parse_alternative_services = true; |
| 8933 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8934 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8935 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8936 | session_deps_.proxy_service = |
| 8937 | ProxyService::CreateFixed(tests[i].proxy_server); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8938 | scoped_ptr<HttpNetworkSession> session( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8939 | SetupSessionForGroupNameTests(GetProtocol(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8940 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8941 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8942 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8943 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8944 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8945 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8946 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8947 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8948 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8949 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8950 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8951 | mock_pool_manager->SetSocketPoolForHTTPProxy(proxy_host, http_proxy_pool); |
| 8952 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 8953 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8954 | |
| 8955 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8956 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8957 | if (tests[i].ssl) |
| 8958 | EXPECT_EQ(tests[i].expected_group_name, |
| 8959 | ssl_conn_pool->last_group_name_received()); |
| 8960 | else |
| 8961 | EXPECT_EQ(tests[i].expected_group_name, |
| 8962 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8963 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8964 | } |
| 8965 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8966 | TEST_P(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8967 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8968 | { |
| 8969 | "socks4://socks_proxy:1080", |
| 8970 | "http://www.example.org/socks4_direct", |
| 8971 | "socks4/www.example.org:80", |
| 8972 | false, |
| 8973 | }, |
| 8974 | { |
| 8975 | "socks5://socks_proxy:1080", |
| 8976 | "http://www.example.org/socks5_direct", |
| 8977 | "socks5/www.example.org:80", |
| 8978 | false, |
| 8979 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8980 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8981 | // SSL Tests |
| 8982 | { |
| 8983 | "socks4://socks_proxy:1080", |
| 8984 | "https://www.example.org/socks4_ssl", |
| 8985 | "socks4/ssl/www.example.org:443", |
| 8986 | true, |
| 8987 | }, |
| 8988 | { |
| 8989 | "socks5://socks_proxy:1080", |
| 8990 | "https://www.example.org/socks5_ssl", |
| 8991 | "socks5/ssl/www.example.org:443", |
| 8992 | true, |
| 8993 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 8994 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8995 | { |
| 8996 | "socks4://socks_proxy:1080", |
| 8997 | "http://host.with.alternate/direct", |
| 8998 | "socks4/ssl/host.with.alternate:443", |
| 8999 | true, |
| 9000 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9001 | }; |
| 9002 | |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 9003 | session_deps_.parse_alternative_services = true; |
| 9004 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9005 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9006 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9007 | session_deps_.proxy_service = |
| 9008 | ProxyService::CreateFixed(tests[i].proxy_server); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9009 | scoped_ptr<HttpNetworkSession> session( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9010 | SetupSessionForGroupNameTests(GetProtocol(), &session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 9011 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9012 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9013 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9014 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9015 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9016 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9017 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9018 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9019 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 9020 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 9021 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9022 | mock_pool_manager->SetSocketPoolForSOCKSProxy(proxy_host, socks_conn_pool); |
| 9023 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9024 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9025 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9026 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9027 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9028 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9029 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9030 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9031 | if (tests[i].ssl) |
| 9032 | EXPECT_EQ(tests[i].expected_group_name, |
| 9033 | ssl_conn_pool->last_group_name_received()); |
| 9034 | else |
| 9035 | EXPECT_EQ(tests[i].expected_group_name, |
| 9036 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9037 | } |
| 9038 | } |
| 9039 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9040 | TEST_P(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9041 | HttpRequestInfo request; |
| 9042 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9043 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9044 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9045 | session_deps_.proxy_service = |
| 9046 | ProxyService::CreateFixed("myproxy:70;foobar:80"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9047 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 9048 | // This simulates failure resolving all hostnames; that means we will fail |
| 9049 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9050 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9051 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9052 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9053 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9054 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9055 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9056 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9057 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9058 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9059 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9060 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9061 | rv = callback.WaitForResult(); |
[email protected] | f7fccee | 2010-09-16 20:53:01 | [diff] [blame] | 9062 | EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9063 | } |
| 9064 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9065 | // Base test to make sure that when the load flags for a request specify to |
| 9066 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9067 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9068 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9069 | // Issue a request, asking to bypass the cache(s). |
| 9070 | HttpRequestInfo request; |
| 9071 | request.method = "GET"; |
| 9072 | request.load_flags = load_flags; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9073 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9074 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 9075 | // Select a host resolver that does caching. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9076 | session_deps_.host_resolver.reset(new MockCachingHostResolver); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9077 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9078 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 9079 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9080 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9081 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9082 | // 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] | 9083 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 9084 | TestCompletionCallback callback; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9085 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9086 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
| 9087 | DEFAULT_PRIORITY, &addrlist, callback.callback(), NULL, BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 9088 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9089 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9090 | EXPECT_EQ(OK, rv); |
| 9091 | |
| 9092 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 9093 | // and confirming it completes synchronously. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9094 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9095 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
| 9096 | DEFAULT_PRIORITY, &addrlist, callback.callback(), NULL, BoundNetLog()); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9097 | ASSERT_EQ(OK, rv); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9098 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9099 | // 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] | 9100 | // we can tell if the next lookup hit the cache, or the "network". |
| 9101 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9102 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9103 | |
| 9104 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 9105 | // 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] | 9106 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9107 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9108 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9109 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9110 | // Run the request. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9111 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9112 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9113 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9114 | |
| 9115 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9116 | // "www.example.org". |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9117 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
| 9118 | } |
| 9119 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9120 | // There are multiple load flags that should trigger the host cache bypass. |
| 9121 | // Test each in isolation: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9122 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9123 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 9124 | } |
| 9125 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9126 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9127 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 9128 | } |
| 9129 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9130 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9131 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 9132 | } |
| 9133 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9134 | // Make sure we can handle an error when writing the request. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9135 | TEST_P(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9136 | HttpRequestInfo request; |
| 9137 | request.method = "GET"; |
| 9138 | request.url = GURL("http://www.foo.com/"); |
| 9139 | request.load_flags = 0; |
| 9140 | |
| 9141 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9142 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9143 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9144 | StaticSocketDataProvider data(NULL, 0, |
| 9145 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9146 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9147 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9148 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9149 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9150 | |
| 9151 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9152 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9153 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9154 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9155 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9156 | |
| 9157 | rv = callback.WaitForResult(); |
| 9158 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9159 | |
| 9160 | IPEndPoint endpoint; |
| 9161 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 9162 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9163 | } |
| 9164 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9165 | // Check that a connection closed after the start of the headers finishes ok. |
| 9166 | TEST_P(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9167 | HttpRequestInfo request; |
| 9168 | request.method = "GET"; |
| 9169 | request.url = GURL("http://www.foo.com/"); |
| 9170 | request.load_flags = 0; |
| 9171 | |
| 9172 | MockRead data_reads[] = { |
| 9173 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9174 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9175 | }; |
| 9176 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9177 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9178 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9179 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9180 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9181 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9182 | |
| 9183 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9184 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9185 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9186 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9187 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9188 | |
| 9189 | rv = callback.WaitForResult(); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9190 | EXPECT_EQ(OK, rv); |
| 9191 | |
| 9192 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9193 | ASSERT_TRUE(response != NULL); |
| 9194 | |
| 9195 | EXPECT_TRUE(response->headers.get() != NULL); |
| 9196 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9197 | |
| 9198 | std::string response_data; |
| 9199 | rv = ReadTransaction(trans.get(), &response_data); |
| 9200 | EXPECT_EQ(OK, rv); |
| 9201 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9202 | |
| 9203 | IPEndPoint endpoint; |
| 9204 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 9205 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9206 | } |
| 9207 | |
| 9208 | // Make sure that a dropped connection while draining the body for auth |
| 9209 | // restart does the right thing. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9210 | TEST_P(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9211 | HttpRequestInfo request; |
| 9212 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9213 | request.url = GURL("http://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9214 | request.load_flags = 0; |
| 9215 | |
| 9216 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9217 | MockWrite( |
| 9218 | "GET / HTTP/1.1\r\n" |
| 9219 | "Host: www.example.org\r\n" |
| 9220 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9221 | }; |
| 9222 | |
| 9223 | MockRead data_reads1[] = { |
| 9224 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 9225 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9226 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9227 | MockRead("Content-Length: 14\r\n\r\n"), |
| 9228 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9229 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9230 | }; |
| 9231 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9232 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9233 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9234 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9235 | |
| 9236 | // After calling trans->RestartWithAuth(), this is the request we should |
| 9237 | // be issuing -- the final header line contains the credentials. |
| 9238 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9239 | MockWrite( |
| 9240 | "GET / HTTP/1.1\r\n" |
| 9241 | "Host: www.example.org\r\n" |
| 9242 | "Connection: keep-alive\r\n" |
| 9243 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9244 | }; |
| 9245 | |
| 9246 | // Lastly, the server responds with the actual content. |
| 9247 | MockRead data_reads2[] = { |
| 9248 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9249 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9250 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9251 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9252 | }; |
| 9253 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9254 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9255 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9256 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9257 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9258 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9259 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9260 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9261 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9262 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9263 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9264 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9265 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9266 | |
| 9267 | rv = callback1.WaitForResult(); |
| 9268 | EXPECT_EQ(OK, rv); |
| 9269 | |
| 9270 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9271 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9272 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9273 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9274 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9275 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9276 | rv = trans->RestartWithAuth( |
| 9277 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9278 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9279 | |
| 9280 | rv = callback2.WaitForResult(); |
| 9281 | EXPECT_EQ(OK, rv); |
| 9282 | |
| 9283 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9284 | ASSERT_TRUE(response != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9285 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 9286 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9287 | } |
| 9288 | |
| 9289 | // Test HTTPS connections going through a proxy that sends extra data. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9290 | TEST_P(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9291 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9292 | |
| 9293 | HttpRequestInfo request; |
| 9294 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9295 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9296 | request.load_flags = 0; |
| 9297 | |
| 9298 | MockRead proxy_reads[] = { |
| 9299 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9300 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9301 | }; |
| 9302 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9303 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9304 | SSLSocketDataProvider ssl(ASYNC, OK); |
[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->AddSocketDataProvider(&data); |
| 9307 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9308 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9309 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9310 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9311 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9312 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9313 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9314 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9315 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9316 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9317 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9318 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9319 | |
| 9320 | rv = callback.WaitForResult(); |
| 9321 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 9322 | } |
| 9323 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9324 | TEST_P(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9325 | HttpRequestInfo request; |
| 9326 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9327 | request.url = GURL("http://www.example.org/"); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9328 | request.load_flags = 0; |
| 9329 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9330 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9331 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9332 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9333 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9334 | MockRead data_reads[] = { |
| 9335 | 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] | 9336 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9337 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9338 | |
| 9339 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9340 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9341 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9342 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9343 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9344 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9345 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9346 | |
| 9347 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9348 | |
| 9349 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9350 | ASSERT_TRUE(response != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9351 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9352 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9353 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9354 | |
| 9355 | std::string response_data; |
| 9356 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 5543cbb | 2012-04-20 16:35:23 | [diff] [blame] | 9357 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9358 | } |
| 9359 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9360 | TEST_P(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9361 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9362 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9363 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 9364 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 9365 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9366 | |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9367 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 9368 | element_readers.push_back(make_scoped_ptr(new UploadFileElementReader( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9369 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
| 9370 | std::numeric_limits<uint64_t>::max(), base::Time()))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9371 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9372 | |
| 9373 | HttpRequestInfo request; |
| 9374 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9375 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9376 | request.upload_data_stream = &upload_data_stream; |
| 9377 | request.load_flags = 0; |
| 9378 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9379 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9380 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9381 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9382 | |
| 9383 | MockRead data_reads[] = { |
| 9384 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 9385 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9386 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9387 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9388 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9389 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9390 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9391 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9392 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9393 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9394 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9395 | |
| 9396 | rv = callback.WaitForResult(); |
| 9397 | EXPECT_EQ(OK, rv); |
| 9398 | |
| 9399 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9400 | ASSERT_TRUE(response != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9401 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9402 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9403 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9404 | |
| 9405 | std::string response_data; |
| 9406 | rv = ReadTransaction(trans.get(), &response_data); |
| 9407 | EXPECT_EQ(OK, rv); |
| 9408 | EXPECT_EQ("hello world", response_data); |
| 9409 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9410 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9411 | } |
| 9412 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9413 | TEST_P(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9414 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9415 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9416 | std::string temp_file_content("Unreadable file."); |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 9417 | ASSERT_TRUE(base::WriteFile(temp_file, temp_file_content.c_str(), |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9418 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 9419 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9420 | |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9421 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9422 | element_readers.push_back(make_scoped_ptr(new UploadFileElementReader( |
| 9423 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
| 9424 | std::numeric_limits<uint64_t>::max(), base::Time()))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9425 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9426 | |
| 9427 | HttpRequestInfo request; |
| 9428 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9429 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9430 | request.upload_data_stream = &upload_data_stream; |
| 9431 | request.load_flags = 0; |
| 9432 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9433 | // If we try to upload an unreadable file, the transaction should fail. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9434 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9435 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9436 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9437 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9438 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9439 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9440 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9441 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9442 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9443 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9444 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9445 | |
| 9446 | rv = callback.WaitForResult(); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9447 | EXPECT_EQ(ERR_ACCESS_DENIED, rv); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9448 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9449 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9450 | } |
| 9451 | |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9452 | TEST_P(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
| 9453 | class FakeUploadElementReader : public UploadElementReader { |
| 9454 | public: |
| 9455 | FakeUploadElementReader() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9456 | ~FakeUploadElementReader() override {} |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9457 | |
| 9458 | const CompletionCallback& callback() const { return callback_; } |
| 9459 | |
| 9460 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9461 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9462 | callback_ = callback; |
| 9463 | return ERR_IO_PENDING; |
| 9464 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9465 | uint64_t GetContentLength() const override { return 0; } |
| 9466 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9467 | int Read(IOBuffer* buf, |
| 9468 | int buf_length, |
| 9469 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9470 | return ERR_FAILED; |
| 9471 | } |
| 9472 | |
| 9473 | private: |
| 9474 | CompletionCallback callback_; |
| 9475 | }; |
| 9476 | |
| 9477 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9478 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 9479 | element_readers.push_back(make_scoped_ptr(fake_reader)); |
| 9480 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9481 | |
| 9482 | HttpRequestInfo request; |
| 9483 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9484 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9485 | request.upload_data_stream = &upload_data_stream; |
| 9486 | request.load_flags = 0; |
| 9487 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9488 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9489 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9490 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9491 | |
| 9492 | StaticSocketDataProvider data; |
| 9493 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9494 | |
| 9495 | TestCompletionCallback callback; |
| 9496 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9497 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9498 | base::MessageLoop::current()->RunUntilIdle(); |
| 9499 | |
| 9500 | // Transaction is pending on request body initialization. |
| 9501 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 9502 | |
| 9503 | // Return Init()'s result after the transaction gets destroyed. |
| 9504 | trans.reset(); |
| 9505 | fake_reader->callback().Run(OK); // Should not crash. |
| 9506 | } |
| 9507 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9508 | // Tests that changes to Auth realms are treated like auth rejections. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9509 | TEST_P(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9510 | HttpRequestInfo request; |
| 9511 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9512 | request.url = GURL("http://www.example.org/"); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9513 | request.load_flags = 0; |
| 9514 | |
| 9515 | // First transaction will request a resource and receive a Basic challenge |
| 9516 | // with realm="first_realm". |
| 9517 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9518 | MockWrite( |
| 9519 | "GET / HTTP/1.1\r\n" |
| 9520 | "Host: www.example.org\r\n" |
| 9521 | "Connection: keep-alive\r\n" |
| 9522 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9523 | }; |
| 9524 | MockRead data_reads1[] = { |
| 9525 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9526 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 9527 | "\r\n"), |
| 9528 | }; |
| 9529 | |
| 9530 | // After calling trans->RestartWithAuth(), provide an Authentication header |
| 9531 | // for first_realm. The server will reject and provide a challenge with |
| 9532 | // second_realm. |
| 9533 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9534 | MockWrite( |
| 9535 | "GET / HTTP/1.1\r\n" |
| 9536 | "Host: www.example.org\r\n" |
| 9537 | "Connection: keep-alive\r\n" |
| 9538 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 9539 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9540 | }; |
| 9541 | MockRead data_reads2[] = { |
| 9542 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9543 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 9544 | "\r\n"), |
| 9545 | }; |
| 9546 | |
| 9547 | // This again fails, and goes back to first_realm. Make sure that the |
| 9548 | // entry is removed from cache. |
| 9549 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9550 | MockWrite( |
| 9551 | "GET / HTTP/1.1\r\n" |
| 9552 | "Host: www.example.org\r\n" |
| 9553 | "Connection: keep-alive\r\n" |
| 9554 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 9555 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9556 | }; |
| 9557 | MockRead data_reads3[] = { |
| 9558 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9559 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 9560 | "\r\n"), |
| 9561 | }; |
| 9562 | |
| 9563 | // Try one last time (with the correct password) and get the resource. |
| 9564 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9565 | MockWrite( |
| 9566 | "GET / HTTP/1.1\r\n" |
| 9567 | "Host: www.example.org\r\n" |
| 9568 | "Connection: keep-alive\r\n" |
| 9569 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 9570 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9571 | }; |
| 9572 | MockRead data_reads4[] = { |
| 9573 | MockRead("HTTP/1.1 200 OK\r\n" |
| 9574 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9575 | "Content-Length: 5\r\n" |
| 9576 | "\r\n" |
| 9577 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9578 | }; |
| 9579 | |
| 9580 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9581 | data_writes1, arraysize(data_writes1)); |
| 9582 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9583 | data_writes2, arraysize(data_writes2)); |
| 9584 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 9585 | data_writes3, arraysize(data_writes3)); |
| 9586 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 9587 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9588 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9589 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 9590 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 9591 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9592 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9593 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9594 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9595 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9596 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9597 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9598 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9599 | // Issue the first request with Authorize headers. There should be a |
| 9600 | // password prompt for first_realm waiting to be filled in after the |
| 9601 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9602 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9603 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9604 | rv = callback1.WaitForResult(); |
| 9605 | EXPECT_EQ(OK, rv); |
| 9606 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9607 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9608 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
| 9609 | ASSERT_FALSE(challenge == NULL); |
| 9610 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9611 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9612 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 9613 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9614 | |
| 9615 | // Issue the second request with an incorrect password. There should be a |
| 9616 | // password prompt for second_realm waiting to be filled in after the |
| 9617 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9618 | TestCompletionCallback callback2; |
| 9619 | rv = trans->RestartWithAuth( |
| 9620 | AuthCredentials(kFirst, kBaz), callback2.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9621 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9622 | rv = callback2.WaitForResult(); |
| 9623 | EXPECT_EQ(OK, rv); |
| 9624 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9625 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9626 | challenge = response->auth_challenge.get(); |
| 9627 | ASSERT_FALSE(challenge == NULL); |
| 9628 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9629 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9630 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 9631 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9632 | |
| 9633 | // Issue the third request with another incorrect password. There should be |
| 9634 | // a password prompt for first_realm waiting to be filled in. If the password |
| 9635 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 9636 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9637 | TestCompletionCallback callback3; |
| 9638 | rv = trans->RestartWithAuth( |
| 9639 | AuthCredentials(kSecond, kFou), callback3.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9640 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9641 | rv = callback3.WaitForResult(); |
| 9642 | EXPECT_EQ(OK, rv); |
| 9643 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9644 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9645 | challenge = response->auth_challenge.get(); |
| 9646 | ASSERT_FALSE(challenge == NULL); |
| 9647 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9648 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9649 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 9650 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9651 | |
| 9652 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9653 | TestCompletionCallback callback4; |
| 9654 | rv = trans->RestartWithAuth( |
| 9655 | AuthCredentials(kFirst, kBar), callback4.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9656 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9657 | rv = callback4.WaitForResult(); |
| 9658 | EXPECT_EQ(OK, rv); |
| 9659 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9660 | ASSERT_TRUE(response != NULL); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9661 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 9662 | } |
| 9663 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9664 | TEST_P(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 9665 | session_deps_.parse_alternative_services = true; |
| 9666 | session_deps_.enable_alternative_service_with_different_host = false; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9667 | |
| 9668 | std::string alternative_service_http_header = |
| 9669 | GetAlternativeServiceHttpHeader(); |
| 9670 | |
| 9671 | MockRead data_reads[] = { |
| 9672 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9673 | MockRead(alternative_service_http_header.c_str()), |
| 9674 | MockRead("\r\n"), |
| 9675 | MockRead("hello world"), |
| 9676 | MockRead(SYNCHRONOUS, OK), |
| 9677 | }; |
| 9678 | |
| 9679 | HttpRequestInfo request; |
| 9680 | request.method = "GET"; |
| 9681 | request.url = GURL("http://www.example.org/"); |
| 9682 | request.load_flags = 0; |
| 9683 | |
| 9684 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9685 | |
| 9686 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9687 | |
| 9688 | TestCompletionCallback callback; |
| 9689 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9690 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9691 | scoped_ptr<HttpTransaction> trans( |
| 9692 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9693 | |
| 9694 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9695 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9696 | |
| 9697 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9698 | HttpServerProperties& http_server_properties = |
| 9699 | *session->http_server_properties(); |
| 9700 | AlternativeServiceVector alternative_service_vector = |
| 9701 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9702 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9703 | |
| 9704 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9705 | |
| 9706 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9707 | ASSERT_TRUE(response != NULL); |
| 9708 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9709 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9710 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9711 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9712 | |
| 9713 | std::string response_data; |
| 9714 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9715 | EXPECT_EQ("hello world", response_data); |
| 9716 | |
| 9717 | alternative_service_vector = |
| 9718 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9719 | ASSERT_EQ(1u, alternative_service_vector.size()); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9720 | EXPECT_EQ(AlternateProtocolFromNextProto(GetProtocol()), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9721 | alternative_service_vector[0].protocol); |
| 9722 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 9723 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 9724 | } |
| 9725 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 9726 | TEST_P(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 9727 | session_deps_.parse_alternative_services = true; |
| 9728 | session_deps_.enable_alternative_service_with_different_host = false; |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 9729 | |
| 9730 | // Set an alternative service for origin. |
| 9731 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9732 | HttpServerProperties& http_server_properties = |
| 9733 | *session->http_server_properties(); |
| 9734 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9735 | AlternativeService alternative_service(QUIC, "", 80); |
| 9736 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 9737 | http_server_properties.SetAlternativeService(http_host_port_pair, |
| 9738 | alternative_service, expiration); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 9739 | AlternativeServiceVector alternative_service_vector = |
| 9740 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9741 | EXPECT_EQ(1u, alternative_service_vector.size()); |
| 9742 | |
| 9743 | // Send a clear header. |
| 9744 | MockRead data_reads[] = { |
| 9745 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9746 | MockRead("Alt-Svc: clear\r\n"), |
| 9747 | MockRead("\r\n"), |
| 9748 | MockRead("hello world"), |
| 9749 | MockRead(SYNCHRONOUS, OK), |
| 9750 | }; |
| 9751 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 9752 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9753 | |
| 9754 | HttpRequestInfo request; |
| 9755 | request.method = "GET"; |
| 9756 | request.url = GURL("http://www.example.org/"); |
| 9757 | request.load_flags = 0; |
| 9758 | |
| 9759 | TestCompletionCallback callback; |
| 9760 | |
| 9761 | scoped_ptr<HttpTransaction> trans( |
| 9762 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9763 | |
| 9764 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9765 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 9766 | |
| 9767 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9768 | ASSERT_TRUE(response != nullptr); |
| 9769 | ASSERT_TRUE(response->headers.get() != nullptr); |
| 9770 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9771 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9772 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9773 | |
| 9774 | std::string response_data; |
| 9775 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9776 | EXPECT_EQ("hello world", response_data); |
| 9777 | |
| 9778 | alternative_service_vector = |
| 9779 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9780 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9781 | } |
| 9782 | |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 9783 | // Alternative Service headers must be ignored when |
| 9784 | // |parse_alternative_services| is false. |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9785 | TEST_P(HttpNetworkTransactionTest, DoNotHonorAlternativeServiceHeader) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 9786 | session_deps_.parse_alternative_services = false; |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9787 | |
| 9788 | std::string alternative_service_http_header = |
| 9789 | GetAlternativeServiceHttpHeader(); |
| 9790 | |
| 9791 | MockRead data_reads[] = { |
| 9792 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9793 | MockRead(alternative_service_http_header.c_str()), |
| 9794 | MockRead("\r\n"), |
| 9795 | MockRead("hello world"), |
| 9796 | MockRead(SYNCHRONOUS, OK), |
| 9797 | }; |
| 9798 | |
| 9799 | HttpRequestInfo request; |
| 9800 | request.method = "GET"; |
| 9801 | request.url = GURL("http://www.example.org/"); |
| 9802 | request.load_flags = 0; |
| 9803 | |
| 9804 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 9805 | |
| 9806 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9807 | |
| 9808 | TestCompletionCallback callback; |
| 9809 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9810 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9811 | scoped_ptr<HttpTransaction> trans( |
| 9812 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9813 | |
| 9814 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9815 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9816 | |
| 9817 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9818 | HttpServerProperties& http_server_properties = |
| 9819 | *session->http_server_properties(); |
| 9820 | AlternativeServiceVector alternative_service_vector = |
| 9821 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9822 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9823 | |
| 9824 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9825 | |
| 9826 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9827 | ASSERT_TRUE(response != nullptr); |
| 9828 | ASSERT_TRUE(response->headers.get() != nullptr); |
| 9829 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9830 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9831 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9832 | |
| 9833 | std::string response_data; |
| 9834 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9835 | EXPECT_EQ("hello world", response_data); |
| 9836 | |
| 9837 | alternative_service_vector = |
| 9838 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9839 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9840 | } |
| 9841 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9842 | TEST_P(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeader) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 9843 | session_deps_.parse_alternative_services = true; |
| 9844 | session_deps_.enable_alternative_service_with_different_host = false; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9845 | |
| 9846 | MockRead data_reads[] = { |
| 9847 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9848 | MockRead("Alt-Svc: "), |
| 9849 | MockRead(GetAlternateProtocolFromParam()), |
bnc | 44858c8 | 2015-10-16 11:57:21 | [diff] [blame] | 9850 | MockRead("=\"www.example.com:443\";p=\"1.0\","), |
bnc | 3f0118e | 2016-02-02 15:42:22 | [diff] [blame] | 9851 | MockRead(GetAlternateProtocolFromParam()), |
| 9852 | MockRead("=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9853 | MockRead("hello world"), |
| 9854 | MockRead(SYNCHRONOUS, OK), |
| 9855 | }; |
| 9856 | |
| 9857 | HttpRequestInfo request; |
| 9858 | request.method = "GET"; |
| 9859 | request.url = GURL("http://www.example.org/"); |
| 9860 | request.load_flags = 0; |
| 9861 | |
| 9862 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9863 | |
| 9864 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9865 | |
| 9866 | TestCompletionCallback callback; |
| 9867 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9868 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9869 | scoped_ptr<HttpTransaction> trans( |
| 9870 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9871 | |
| 9872 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9873 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9874 | |
| 9875 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9876 | HttpServerProperties& http_server_properties = |
| 9877 | *session->http_server_properties(); |
| 9878 | AlternativeServiceVector alternative_service_vector = |
| 9879 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9880 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9881 | |
| 9882 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9883 | |
| 9884 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9885 | ASSERT_TRUE(response != NULL); |
| 9886 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9887 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9888 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9889 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9890 | |
| 9891 | std::string response_data; |
| 9892 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9893 | EXPECT_EQ("hello world", response_data); |
| 9894 | |
| 9895 | alternative_service_vector = |
| 9896 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9897 | ASSERT_EQ(2u, alternative_service_vector.size()); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9898 | EXPECT_EQ(AlternateProtocolFromNextProto(GetProtocol()), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9899 | alternative_service_vector[0].protocol); |
| 9900 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 9901 | EXPECT_EQ(443, alternative_service_vector[0].port); |
bnc | 3f0118e | 2016-02-02 15:42:22 | [diff] [blame] | 9902 | EXPECT_EQ(AlternateProtocolFromNextProto(GetProtocol()), |
| 9903 | alternative_service_vector[1].protocol); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9904 | EXPECT_EQ("www.example.org", alternative_service_vector[1].host); |
| 9905 | EXPECT_EQ(1234, alternative_service_vector[1].port); |
| 9906 | } |
| 9907 | |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 9908 | // Alternate Protocol headers must be honored even if |
| 9909 | // |parse_alternative_services| is false. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9910 | TEST_P(HttpNetworkTransactionTest, HonorAlternateProtocolHeader) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 9911 | session_deps_.parse_alternative_services = false; |
[email protected] | a2cb812 | 2010-03-10 17:22:42 | [diff] [blame] | 9912 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9913 | std::string alternate_protocol_http_header = |
| 9914 | GetAlternateProtocolHttpHeader(); |
| 9915 | |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9916 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9917 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9918 | MockRead(alternate_protocol_http_header.c_str()), |
| 9919 | MockRead("\r\n"), |
| 9920 | MockRead("hello world"), |
| 9921 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9922 | }; |
| 9923 | |
| 9924 | HttpRequestInfo request; |
| 9925 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9926 | request.url = GURL("http://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9927 | request.load_flags = 0; |
| 9928 | |
| 9929 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9930 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9931 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9932 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9933 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9934 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9935 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9936 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9937 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9938 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9939 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9940 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 9941 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9942 | HostPortPair http_host_port_pair("www.example.org", 80); |
[email protected] | 9801e370 | 2014-03-07 09:33:55 | [diff] [blame] | 9943 | HttpServerProperties& http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9944 | *session->http_server_properties(); |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9945 | AlternativeServiceVector alternative_service_vector = |
| 9946 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9947 | EXPECT_TRUE(alternative_service_vector.empty()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9948 | |
| 9949 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9950 | |
| 9951 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9952 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9953 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9954 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9955 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9956 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9957 | |
| 9958 | std::string response_data; |
| 9959 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9960 | EXPECT_EQ("hello world", response_data); |
| 9961 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9962 | alternative_service_vector = |
| 9963 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9964 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9965 | EXPECT_EQ(443, alternative_service_vector[0].port); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9966 | EXPECT_EQ(AlternateProtocolFromNextProto(GetProtocol()), |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9967 | alternative_service_vector[0].protocol); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9968 | } |
| 9969 | |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9970 | TEST_P(HttpNetworkTransactionTest, EmptyAlternateProtocolHeader) { |
rch | 3f4b845 | 2016-02-23 16:59:32 | [diff] [blame] | 9971 | session_deps_.parse_alternative_services = false; |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 9972 | session_deps_.enable_alternative_service_with_different_host = false; |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9973 | |
| 9974 | MockRead data_reads[] = { |
| 9975 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9976 | MockRead("Alternate-Protocol: \r\n\r\n"), |
| 9977 | MockRead("hello world"), |
| 9978 | MockRead(SYNCHRONOUS, OK), |
| 9979 | }; |
| 9980 | |
| 9981 | HttpRequestInfo request; |
| 9982 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9983 | request.url = GURL("http://www.example.org/"); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9984 | request.load_flags = 0; |
| 9985 | |
| 9986 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9987 | |
| 9988 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9989 | |
| 9990 | TestCompletionCallback callback; |
| 9991 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9992 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9993 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9994 | HostPortPair http_host_port_pair("www.example.org", 80); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9995 | HttpServerProperties& http_server_properties = |
| 9996 | *session->http_server_properties(); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9997 | AlternativeService alternative_service(QUIC, "", 80); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9998 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 9999 | http_server_properties.SetAlternativeService(http_host_port_pair, |
| 10000 | alternative_service, expiration); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10001 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10002 | AlternativeServiceVector alternative_service_vector = |
| 10003 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 10004 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 10005 | EXPECT_EQ(QUIC, alternative_service_vector[0].protocol); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 10006 | |
| 10007 | scoped_ptr<HttpTransaction> trans( |
| 10008 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 10009 | |
| 10010 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10011 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10012 | |
| 10013 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10014 | |
| 10015 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10016 | ASSERT_TRUE(response != NULL); |
| 10017 | ASSERT_TRUE(response->headers.get() != NULL); |
| 10018 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10019 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10020 | EXPECT_FALSE(response->was_npn_negotiated); |
| 10021 | |
| 10022 | std::string response_data; |
| 10023 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10024 | EXPECT_EQ("hello world", response_data); |
| 10025 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10026 | alternative_service_vector = |
| 10027 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 10028 | EXPECT_TRUE(alternative_service_vector.empty()); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 10029 | } |
| 10030 | |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10031 | // When |session_deps_.parse_alternative_services = true| and the response has |
| 10032 | // an Alt-Svc header, then the Alternate-Protocol header is not parsed. |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10033 | TEST_P(HttpNetworkTransactionTest, AltSvcOverwritesAlternateProtocol) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10034 | session_deps_.parse_alternative_services = true; |
| 10035 | session_deps_.enable_alternative_service_with_different_host = false; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10036 | |
| 10037 | std::string alternative_service_http_header = |
| 10038 | GetAlternativeServiceHttpHeader(); |
| 10039 | std::string alternate_protocol_http_header = GetAlternateProtocolHttpHeader(); |
| 10040 | |
| 10041 | MockRead data_reads[] = { |
| 10042 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10043 | MockRead(alternative_service_http_header.c_str()), |
| 10044 | MockRead(alternate_protocol_http_header.c_str()), |
| 10045 | MockRead("\r\n"), |
| 10046 | MockRead("hello world"), |
| 10047 | MockRead(SYNCHRONOUS, OK), |
| 10048 | }; |
| 10049 | |
| 10050 | HttpRequestInfo request; |
| 10051 | request.method = "GET"; |
| 10052 | request.url = GURL("http://www.example.org/"); |
| 10053 | request.load_flags = 0; |
| 10054 | |
| 10055 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10056 | |
| 10057 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10058 | |
| 10059 | TestCompletionCallback callback; |
| 10060 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10061 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10062 | scoped_ptr<HttpTransaction> trans( |
| 10063 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 10064 | |
| 10065 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10066 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10067 | |
| 10068 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 10069 | HttpServerProperties& http_server_properties = |
| 10070 | *session->http_server_properties(); |
| 10071 | AlternativeServiceVector alternative_service_vector = |
| 10072 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 10073 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 10074 | |
| 10075 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10076 | |
| 10077 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10078 | ASSERT_TRUE(response != NULL); |
| 10079 | ASSERT_TRUE(response->headers.get() != NULL); |
| 10080 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10081 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10082 | EXPECT_FALSE(response->was_npn_negotiated); |
| 10083 | |
| 10084 | std::string response_data; |
| 10085 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10086 | EXPECT_EQ("hello world", response_data); |
| 10087 | |
| 10088 | alternative_service_vector = |
| 10089 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 10090 | ASSERT_EQ(1u, alternative_service_vector.size()); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10091 | EXPECT_EQ(AlternateProtocolFromNextProto(GetProtocol()), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10092 | alternative_service_vector[0].protocol); |
| 10093 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 10094 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 10095 | } |
| 10096 | |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10097 | // When |enable_alternative_service_with_different_host| is false, do not |
| 10098 | // observe alternative service entries that point to a different host. |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 10099 | TEST_P(HttpNetworkTransactionTest, DisableAlternativeServiceToDifferentHost) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10100 | session_deps_.parse_alternative_services = true; |
| 10101 | session_deps_.enable_alternative_service_with_different_host = false; |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 10102 | |
| 10103 | HttpRequestInfo request; |
| 10104 | request.method = "GET"; |
| 10105 | request.url = GURL("http://www.example.org/"); |
| 10106 | request.load_flags = 0; |
| 10107 | |
| 10108 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10109 | StaticSocketDataProvider first_data; |
| 10110 | first_data.set_connect_data(mock_connect); |
| 10111 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 10112 | |
| 10113 | MockRead data_reads[] = { |
| 10114 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10115 | MockRead(ASYNC, OK), |
| 10116 | }; |
| 10117 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), |
| 10118 | nullptr, 0); |
| 10119 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10120 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10121 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 10122 | |
| 10123 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 10124 | session->http_server_properties(); |
| 10125 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10126 | AlternateProtocolFromNextProto(GetProtocol()), "different.example.org", |
| 10127 | 80); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 10128 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10129 | http_server_properties->SetAlternativeService( |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10130 | HostPortPair::FromURL(request.url), alternative_service, expiration); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 10131 | |
| 10132 | scoped_ptr<HttpTransaction> trans( |
| 10133 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 10134 | TestCompletionCallback callback; |
| 10135 | |
| 10136 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10137 | // The connetion to origin was refused, and the alternative service should not |
| 10138 | // be used (even though mock data are there), therefore the request should |
| 10139 | // fail. |
| 10140 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.GetResult(rv)); |
| 10141 | } |
| 10142 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10143 | TEST_P(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
| 10144 | HostPortPair origin("origin.example.org", 443); |
| 10145 | HostPortPair alternative("alternative.example.org", 443); |
| 10146 | std::string origin_url = "https://origin.example.org:443"; |
| 10147 | std::string alternative_url = "https://alternative.example.org:443"; |
| 10148 | |
| 10149 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 10150 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10151 | ssl.SetNextProto(kProtoHTTP11); |
| 10152 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10153 | |
| 10154 | // HTTP/1.1 data for request. |
| 10155 | MockWrite http_writes[] = { |
| 10156 | MockWrite("GET / HTTP/1.1\r\n" |
| 10157 | "Host: alternative.example.org\r\n" |
| 10158 | "Connection: keep-alive\r\n\r\n"), |
| 10159 | }; |
| 10160 | |
| 10161 | MockRead http_reads[] = { |
| 10162 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10163 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10164 | "Content-Length: 40\r\n\r\n" |
| 10165 | "first HTTP/1.1 response from alternative"), |
| 10166 | }; |
| 10167 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10168 | http_writes, arraysize(http_writes)); |
| 10169 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10170 | |
| 10171 | StaticSocketDataProvider data_refused; |
| 10172 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10173 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10174 | |
| 10175 | // Set up a QUIC alternative service for origin. |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10176 | session_deps_.parse_alternative_services = true; |
| 10177 | session_deps_.enable_alternative_service_with_different_host = false; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10178 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10179 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 10180 | session->http_server_properties(); |
| 10181 | AlternativeService alternative_service(QUIC, alternative); |
| 10182 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10183 | http_server_properties->SetAlternativeService(origin, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10184 | expiration); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10185 | // Mark the QUIC alternative service as broken. |
| 10186 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 10187 | |
| 10188 | scoped_ptr<HttpTransaction> trans( |
| 10189 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 10190 | HttpRequestInfo request; |
| 10191 | request.method = "GET"; |
| 10192 | request.url = GURL(origin_url); |
| 10193 | request.load_flags = 0; |
| 10194 | TestCompletionCallback callback; |
| 10195 | NetErrorDetails details; |
| 10196 | EXPECT_FALSE(details.quic_broken); |
| 10197 | |
| 10198 | trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10199 | trans->PopulateNetErrorDetails(&details); |
| 10200 | EXPECT_TRUE(details.quic_broken); |
| 10201 | } |
| 10202 | |
| 10203 | TEST_P(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
| 10204 | HostPortPair origin("origin.example.org", 443); |
| 10205 | HostPortPair alternative1("alternative1.example.org", 443); |
| 10206 | HostPortPair alternative2("alternative2.example.org", 443); |
| 10207 | std::string origin_url = "https://origin.example.org:443"; |
| 10208 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 10209 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 10210 | |
| 10211 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 10212 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10213 | ssl.SetNextProto(kProtoHTTP11); |
| 10214 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10215 | |
| 10216 | // HTTP/1.1 data for request. |
| 10217 | MockWrite http_writes[] = { |
| 10218 | MockWrite("GET / HTTP/1.1\r\n" |
| 10219 | "Host: alternative1.example.org\r\n" |
| 10220 | "Connection: keep-alive\r\n\r\n"), |
| 10221 | }; |
| 10222 | |
| 10223 | MockRead http_reads[] = { |
| 10224 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10225 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10226 | "Content-Length: 40\r\n\r\n" |
| 10227 | "first HTTP/1.1 response from alternative1"), |
| 10228 | }; |
| 10229 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10230 | http_writes, arraysize(http_writes)); |
| 10231 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10232 | |
| 10233 | StaticSocketDataProvider data_refused; |
| 10234 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10235 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10236 | |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10237 | session_deps_.parse_alternative_services = true; |
| 10238 | session_deps_.enable_alternative_service_with_different_host = true; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10239 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10240 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 10241 | session->http_server_properties(); |
| 10242 | |
| 10243 | // Set up two QUIC alternative services for origin. |
| 10244 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 10245 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10246 | |
| 10247 | AlternativeService alternative_service1(QUIC, alternative1); |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10248 | AlternativeServiceInfo alternative_service_info1(alternative_service1, |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10249 | expiration); |
| 10250 | alternative_service_info_vector.push_back(alternative_service_info1); |
| 10251 | AlternativeService alternative_service2(QUIC, alternative2); |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10252 | AlternativeServiceInfo alternative_service_info2(alternative_service2, |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10253 | expiration); |
| 10254 | alternative_service_info_vector.push_back(alternative_service_info2); |
| 10255 | |
| 10256 | http_server_properties->SetAlternativeServices( |
| 10257 | origin, alternative_service_info_vector); |
| 10258 | |
| 10259 | // Mark one of the QUIC alternative service as broken. |
| 10260 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
| 10261 | |
| 10262 | const AlternativeServiceVector alternative_service_vector = |
| 10263 | http_server_properties->GetAlternativeServices(origin); |
| 10264 | |
| 10265 | scoped_ptr<HttpTransaction> trans( |
| 10266 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 10267 | HttpRequestInfo request; |
| 10268 | request.method = "GET"; |
| 10269 | request.url = GURL(origin_url); |
| 10270 | request.load_flags = 0; |
| 10271 | TestCompletionCallback callback; |
| 10272 | NetErrorDetails details; |
| 10273 | EXPECT_FALSE(details.quic_broken); |
| 10274 | |
| 10275 | trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10276 | trans->PopulateNetErrorDetails(&details); |
| 10277 | EXPECT_FALSE(details.quic_broken); |
| 10278 | } |
| 10279 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10280 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10281 | MarkBrokenAlternateProtocolAndFallback) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10282 | session_deps_.parse_alternative_services = true; |
| 10283 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10284 | |
| 10285 | HttpRequestInfo request; |
| 10286 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10287 | request.url = GURL("http://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10288 | request.load_flags = 0; |
| 10289 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10290 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10291 | StaticSocketDataProvider first_data; |
| 10292 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10293 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10294 | |
| 10295 | MockRead data_reads[] = { |
| 10296 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10297 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10298 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10299 | }; |
| 10300 | StaticSocketDataProvider second_data( |
| 10301 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10302 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10303 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10304 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10305 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10306 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10307 | session->http_server_properties(); |
bnc | 8445b300 | 2015-03-13 01:57:09 | [diff] [blame] | 10308 | const HostPortPair host_port_pair = HostPortPair::FromURL(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10309 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 10310 | // port 80 (another restricted port). |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10311 | const AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10312 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10313 | 666); // Port is ignored by MockConnect anyway. |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10314 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10315 | http_server_properties->SetAlternativeService( |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10316 | host_port_pair, alternative_service, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10317 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10318 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10319 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10320 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10321 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10322 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10323 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10324 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10325 | |
| 10326 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10327 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10328 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10329 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10330 | |
| 10331 | std::string response_data; |
| 10332 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10333 | EXPECT_EQ("hello world", response_data); |
| 10334 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10335 | const AlternativeServiceVector alternative_service_vector = |
| 10336 | http_server_properties->GetAlternativeServices(host_port_pair); |
| 10337 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 10338 | EXPECT_EQ(alternative_service, alternative_service_vector[0]); |
| 10339 | EXPECT_TRUE(http_server_properties->IsAlternativeServiceBroken( |
| 10340 | alternative_service_vector[0])); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10341 | } |
| 10342 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10343 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10344 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10345 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10346 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10347 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10348 | AlternateProtocolPortRestrictedBlocked) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10349 | session_deps_.parse_alternative_services = true; |
| 10350 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10351 | |
| 10352 | HttpRequestInfo restricted_port_request; |
| 10353 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10354 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10355 | restricted_port_request.load_flags = 0; |
| 10356 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10357 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10358 | StaticSocketDataProvider first_data; |
| 10359 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10360 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10361 | |
| 10362 | MockRead data_reads[] = { |
| 10363 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10364 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10365 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10366 | }; |
| 10367 | StaticSocketDataProvider second_data( |
| 10368 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10369 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10370 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10371 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10372 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10373 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10374 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10375 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10376 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10377 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10378 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10379 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10380 | http_server_properties->SetAlternativeService( |
| 10381 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10382 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10383 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10384 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10385 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10386 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10387 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10388 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10389 | &restricted_port_request, |
| 10390 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10391 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10392 | // Invalid change to unrestricted port should fail. |
| 10393 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10394 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10395 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10396 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 10397 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 10398 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10399 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10400 | AlternateProtocolPortRestrictedPermitted) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10401 | session_deps_.parse_alternative_services = true; |
| 10402 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10403 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10404 | |
| 10405 | HttpRequestInfo restricted_port_request; |
| 10406 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10407 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10408 | restricted_port_request.load_flags = 0; |
| 10409 | |
| 10410 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10411 | StaticSocketDataProvider first_data; |
| 10412 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10413 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10414 | |
| 10415 | MockRead data_reads[] = { |
| 10416 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10417 | MockRead("hello world"), |
| 10418 | MockRead(ASYNC, OK), |
| 10419 | }; |
| 10420 | StaticSocketDataProvider second_data( |
| 10421 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10422 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10423 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10424 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10425 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10426 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10427 | session->http_server_properties(); |
| 10428 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10429 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10430 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10431 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10432 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10433 | http_server_properties->SetAlternativeService( |
| 10434 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10435 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10436 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10437 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10438 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10439 | TestCompletionCallback callback; |
| 10440 | |
| 10441 | EXPECT_EQ(ERR_IO_PENDING, trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10442 | &restricted_port_request, |
| 10443 | callback.callback(), BoundNetLog())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10444 | // Change to unrestricted port should succeed. |
| 10445 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10446 | } |
| 10447 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10448 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10449 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10450 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10451 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10452 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10453 | AlternateProtocolPortRestrictedAllowed) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10454 | session_deps_.parse_alternative_services = true; |
| 10455 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10456 | |
| 10457 | HttpRequestInfo restricted_port_request; |
| 10458 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10459 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10460 | restricted_port_request.load_flags = 0; |
| 10461 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10462 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10463 | StaticSocketDataProvider first_data; |
| 10464 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10465 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10466 | |
| 10467 | MockRead data_reads[] = { |
| 10468 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10469 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10470 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10471 | }; |
| 10472 | StaticSocketDataProvider second_data( |
| 10473 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10474 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10475 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10476 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10477 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10478 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10479 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10480 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10481 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10482 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10483 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10484 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10485 | http_server_properties->SetAlternativeService( |
| 10486 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10487 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10488 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10489 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10490 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10491 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10492 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10493 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10494 | &restricted_port_request, |
| 10495 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10496 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10497 | // Valid change to restricted port should pass. |
| 10498 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10499 | } |
| 10500 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10501 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10502 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10503 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10504 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10505 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10506 | AlternateProtocolPortUnrestrictedAllowed1) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10507 | session_deps_.parse_alternative_services = true; |
| 10508 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10509 | |
| 10510 | HttpRequestInfo unrestricted_port_request; |
| 10511 | unrestricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10512 | unrestricted_port_request.url = GURL("http://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10513 | unrestricted_port_request.load_flags = 0; |
| 10514 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10515 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10516 | StaticSocketDataProvider first_data; |
| 10517 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10518 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10519 | |
| 10520 | MockRead data_reads[] = { |
| 10521 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10522 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10523 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10524 | }; |
| 10525 | StaticSocketDataProvider second_data( |
| 10526 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10527 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10528 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10529 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10530 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10531 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10532 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10533 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10534 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10535 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10536 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10537 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10538 | http_server_properties->SetAlternativeService( |
| 10539 | HostPortPair::FromURL(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10540 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10541 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10542 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10543 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10544 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10545 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10546 | int rv = trans->Start( |
| 10547 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10548 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10549 | // Valid change to restricted port should pass. |
| 10550 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10551 | } |
| 10552 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10553 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10554 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10555 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10556 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10557 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10558 | AlternateProtocolPortUnrestrictedAllowed2) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10559 | session_deps_.parse_alternative_services = true; |
| 10560 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10561 | |
| 10562 | HttpRequestInfo unrestricted_port_request; |
| 10563 | unrestricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10564 | unrestricted_port_request.url = GURL("http://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10565 | unrestricted_port_request.load_flags = 0; |
| 10566 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10567 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10568 | StaticSocketDataProvider first_data; |
| 10569 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10570 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10571 | |
| 10572 | MockRead data_reads[] = { |
| 10573 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10574 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10575 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10576 | }; |
| 10577 | StaticSocketDataProvider second_data( |
| 10578 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10579 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10580 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10581 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10582 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10583 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10584 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 10585 | const int kUnrestrictedAlternatePort = 1025; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10586 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10587 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10588 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10589 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10590 | http_server_properties->SetAlternativeService( |
| 10591 | HostPortPair::FromURL(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10592 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10593 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10594 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10595 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10596 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10597 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10598 | int rv = trans->Start( |
| 10599 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10600 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10601 | // Valid change to an unrestricted port should pass. |
| 10602 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10603 | } |
| 10604 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10605 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10606 | // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job |
| 10607 | // once the alternate protocol request fails. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10608 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10609 | session_deps_.parse_alternative_services = true; |
| 10610 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10611 | |
| 10612 | HttpRequestInfo request; |
| 10613 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10614 | request.url = GURL("http://www.example.org/"); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10615 | request.load_flags = 0; |
| 10616 | |
| 10617 | // The alternate protocol request will error out before we attempt to connect, |
| 10618 | // so only the standard HTTP request will try to connect. |
| 10619 | MockRead data_reads[] = { |
| 10620 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10621 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10622 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10623 | }; |
| 10624 | StaticSocketDataProvider data( |
| 10625 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10626 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10627 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10628 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10629 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10630 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10631 | session->http_server_properties(); |
| 10632 | const int kUnsafePort = 7; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10633 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10634 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10635 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10636 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10637 | http_server_properties->SetAlternativeService( |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10638 | HostPortPair::FromURL(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10639 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10640 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10641 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10642 | TestCompletionCallback callback; |
| 10643 | |
| 10644 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10645 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10646 | // The HTTP request should succeed. |
| 10647 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10648 | |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10649 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10650 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10651 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10652 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10653 | |
| 10654 | std::string response_data; |
| 10655 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10656 | EXPECT_EQ("hello world", response_data); |
| 10657 | } |
| 10658 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10659 | TEST_P(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
rch | 3f4b845 | 2016-02-23 16:59:32 | [diff] [blame] | 10660 | session_deps_.parse_alternative_services = false; |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10661 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10662 | |
| 10663 | HttpRequestInfo request; |
| 10664 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10665 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10666 | request.load_flags = 0; |
| 10667 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10668 | std::string alternate_protocol_http_header = |
| 10669 | GetAlternateProtocolHttpHeader(); |
| 10670 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10671 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10672 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10673 | MockRead(alternate_protocol_http_header.c_str()), |
| 10674 | MockRead("\r\n"), |
| 10675 | MockRead("hello world"), |
| 10676 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10677 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10678 | |
| 10679 | StaticSocketDataProvider first_transaction( |
| 10680 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10681 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10682 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10683 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10684 | ssl.SetNextProto(GetProtocol()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10685 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10686 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10687 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10688 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10689 | scoped_ptr<SpdyFrame> req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 10690 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10691 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10692 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10693 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10694 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10695 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10696 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10697 | }; |
| 10698 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10699 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10700 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10701 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10702 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10703 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10704 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10705 | NULL, 0, NULL, 0); |
| 10706 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10707 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10708 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10709 | &hanging_non_alternate_protocol_socket); |
| 10710 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10711 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10712 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10713 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10714 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10715 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10716 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10717 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10718 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10719 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10720 | |
| 10721 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10722 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10723 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10724 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10725 | |
| 10726 | std::string response_data; |
| 10727 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10728 | EXPECT_EQ("hello world", response_data); |
| 10729 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10730 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10731 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10732 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10733 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10734 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10735 | |
| 10736 | response = trans->GetResponseInfo(); |
| 10737 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10738 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 10739 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10740 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10741 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10742 | |
| 10743 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10744 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10745 | } |
| 10746 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10747 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
rch | 3f4b845 | 2016-02-23 16:59:32 | [diff] [blame] | 10748 | session_deps_.parse_alternative_services = false; |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10749 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10750 | |
| 10751 | HttpRequestInfo request; |
| 10752 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10753 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10754 | request.load_flags = 0; |
| 10755 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10756 | std::string alternate_protocol_http_header = |
| 10757 | GetAlternateProtocolHttpHeader(); |
| 10758 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10759 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10760 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10761 | MockRead(alternate_protocol_http_header.c_str()), |
| 10762 | MockRead("\r\n"), |
| 10763 | MockRead("hello world"), |
| 10764 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10765 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10766 | }; |
| 10767 | |
| 10768 | StaticSocketDataProvider first_transaction( |
| 10769 | data_reads, arraysize(data_reads), NULL, 0); |
| 10770 | // Socket 1 is the HTTP transaction with the Alternate-Protocol header. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10771 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10772 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10773 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10774 | StaticSocketDataProvider hanging_socket1(NULL, 0, NULL, 0); |
| 10775 | hanging_socket1.set_connect_data(never_finishing_connect); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10776 | // Socket 2 and 3 are the hanging Alternate-Protocol and |
| 10777 | // non-Alternate-Protocol jobs from the 2nd transaction. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10778 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 10779 | |
| 10780 | StaticSocketDataProvider hanging_socket2(NULL, 0, NULL, 0); |
| 10781 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 10782 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10783 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10784 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10785 | ssl.SetNextProto(GetProtocol()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10786 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10787 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10788 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10789 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10790 | scoped_ptr<SpdyFrame> req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 10791 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10792 | scoped_ptr<SpdyFrame> req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 10793 | spdy_util_.ConstructSpdyGet(nullptr, 0, 3, LOWEST, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10794 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10795 | CreateMockWrite(*req1, 0), CreateMockWrite(*req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10796 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10797 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10798 | scoped_ptr<SpdyFrame> data1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 10799 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 10800 | scoped_ptr<SpdyFrame> data2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10801 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10802 | CreateMockRead(*resp1, 2), |
| 10803 | CreateMockRead(*data1, 3), |
| 10804 | CreateMockRead(*resp2, 4), |
| 10805 | CreateMockRead(*data2, 5), |
| 10806 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10807 | }; |
| 10808 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10809 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10810 | arraysize(spdy_writes)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10811 | // Socket 4 is the successful Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10812 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10813 | |
| 10814 | // Socket 5 is the unsuccessful non-Alternate-Protocol for transaction 3. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10815 | StaticSocketDataProvider hanging_socket3(NULL, 0, NULL, 0); |
| 10816 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 10817 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10818 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10819 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10820 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10821 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10822 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10823 | int rv = trans1.Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10824 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10825 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 10826 | |
| 10827 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 10828 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10829 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10830 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10831 | |
| 10832 | std::string response_data; |
| 10833 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 10834 | EXPECT_EQ("hello world", response_data); |
| 10835 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10836 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10837 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10838 | rv = trans2.Start(&request, callback2.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10839 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10840 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10841 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10842 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10843 | rv = trans3.Start(&request, callback3.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10844 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10845 | |
| 10846 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 10847 | EXPECT_EQ(OK, callback3.WaitForResult()); |
| 10848 | |
| 10849 | response = trans2.GetResponseInfo(); |
| 10850 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10851 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 10852 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10853 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10854 | EXPECT_TRUE(response->was_npn_negotiated); |
| 10855 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 10856 | EXPECT_EQ("hello!", response_data); |
| 10857 | |
| 10858 | response = trans3.GetResponseInfo(); |
| 10859 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10860 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 10861 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10862 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10863 | EXPECT_TRUE(response->was_npn_negotiated); |
| 10864 | ASSERT_EQ(OK, ReadTransaction(&trans3, &response_data)); |
| 10865 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10866 | } |
| 10867 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10868 | TEST_P(HttpNetworkTransactionTest, StallAlternateProtocolForNpnSpdy) { |
rch | 3f4b845 | 2016-02-23 16:59:32 | [diff] [blame] | 10869 | session_deps_.parse_alternative_services = false; |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10870 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10871 | |
| 10872 | HttpRequestInfo request; |
| 10873 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10874 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10875 | request.load_flags = 0; |
| 10876 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10877 | std::string alternate_protocol_http_header = |
| 10878 | GetAlternateProtocolHttpHeader(); |
| 10879 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10880 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10881 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10882 | MockRead(alternate_protocol_http_header.c_str()), |
| 10883 | MockRead("\r\n"), |
| 10884 | MockRead("hello world"), |
| 10885 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10886 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10887 | }; |
| 10888 | |
| 10889 | StaticSocketDataProvider first_transaction( |
| 10890 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10891 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10892 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10893 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10894 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10895 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10896 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10897 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10898 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 10899 | NULL, 0, NULL, 0); |
| 10900 | hanging_alternate_protocol_socket.set_connect_data( |
| 10901 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10902 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10903 | &hanging_alternate_protocol_socket); |
| 10904 | |
| 10905 | // 2nd request is just a copy of the first one, over HTTP again. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10906 | StaticSocketDataProvider second_transaction(data_reads, arraysize(data_reads), |
| 10907 | NULL, 0); |
| 10908 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10909 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10910 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10911 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10912 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10913 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10914 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10915 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10916 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10917 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10918 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10919 | |
| 10920 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10921 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10922 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10923 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10924 | |
| 10925 | std::string response_data; |
| 10926 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10927 | EXPECT_EQ("hello world", response_data); |
| 10928 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10929 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10930 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10931 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10932 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10933 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10934 | |
| 10935 | response = trans->GetResponseInfo(); |
| 10936 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10937 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10938 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10939 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10940 | EXPECT_FALSE(response->was_npn_negotiated); |
| 10941 | |
| 10942 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10943 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10944 | } |
| 10945 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10946 | class CapturingProxyResolver : public ProxyResolver { |
| 10947 | public: |
sammc | e90c921 | 2015-05-27 23:43:35 | [diff] [blame] | 10948 | CapturingProxyResolver() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10949 | ~CapturingProxyResolver() override {} |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10950 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10951 | int GetProxyForURL(const GURL& url, |
| 10952 | ProxyInfo* results, |
| 10953 | const CompletionCallback& callback, |
eroman | 9c8f424 | 2016-02-29 21:16:54 | [diff] [blame] | 10954 | RequestHandle* request, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10955 | const BoundNetLog& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 10956 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 10957 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 10958 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10959 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 10960 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10961 | } |
| 10962 | |
eroman | 9c8f424 | 2016-02-29 21:16:54 | [diff] [blame] | 10963 | void CancelRequest(RequestHandle request) override { NOTREACHED(); } |
| 10964 | |
| 10965 | LoadState GetLoadState(RequestHandle request) const override { |
| 10966 | NOTREACHED(); |
| 10967 | return LOAD_STATE_IDLE; |
| 10968 | } |
| 10969 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 10970 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 10971 | |
| 10972 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10973 | std::vector<GURL> resolved_; |
| 10974 | |
| 10975 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 10976 | }; |
| 10977 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 10978 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 10979 | public: |
| 10980 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 10981 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 10982 | |
| 10983 | int CreateProxyResolver( |
| 10984 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
| 10985 | scoped_ptr<ProxyResolver>* resolver, |
| 10986 | const net::CompletionCallback& callback, |
| 10987 | scoped_ptr<Request>* request) override { |
| 10988 | resolver->reset(new ForwardingProxyResolver(resolver_)); |
| 10989 | return OK; |
| 10990 | } |
| 10991 | |
| 10992 | private: |
| 10993 | ProxyResolver* resolver_; |
| 10994 | }; |
| 10995 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10996 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10997 | UseAlternateProtocolForTunneledNpnSpdy) { |
rch | 3f4b845 | 2016-02-23 16:59:32 | [diff] [blame] | 10998 | session_deps_.parse_alternative_services = false; |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10999 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11000 | |
| 11001 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11002 | proxy_config.set_auto_detect(true); |
| 11003 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 11004 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11005 | CapturingProxyResolver capturing_proxy_resolver; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11006 | session_deps_.proxy_service.reset(new ProxyService( |
csharrison | b7e3a08 | 2015-09-22 19:13:04 | [diff] [blame] | 11007 | make_scoped_ptr(new ProxyConfigServiceFixed(proxy_config)), |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11008 | make_scoped_ptr( |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11009 | new CapturingProxyResolverFactory(&capturing_proxy_resolver)), |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 11010 | NULL)); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11011 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11012 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11013 | |
| 11014 | HttpRequestInfo request; |
| 11015 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11016 | request.url = GURL("http://www.example.org/"); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11017 | request.load_flags = 0; |
| 11018 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 11019 | std::string alternate_protocol_http_header = |
| 11020 | GetAlternateProtocolHttpHeader(); |
| 11021 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11022 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11023 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11024 | MockRead(alternate_protocol_http_header.c_str()), |
| 11025 | MockRead("\r\n"), |
| 11026 | MockRead("hello world"), |
| 11027 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11028 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11029 | }; |
| 11030 | |
| 11031 | StaticSocketDataProvider first_transaction( |
| 11032 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11033 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11034 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11035 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 11036 | ssl.SetNextProto(GetProtocol()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11037 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 11038 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11039 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11040 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11041 | scoped_ptr<SpdyFrame> req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 11042 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11043 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11044 | MockWrite(ASYNC, 0, |
| 11045 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11046 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11047 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 11048 | CreateMockWrite(*req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11049 | }; |
| 11050 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11051 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 11052 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11053 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11054 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11055 | MockRead spdy_reads[] = { |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 11056 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(*resp.get(), 3), |
| 11057 | CreateMockRead(*data.get(), 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11058 | }; |
| 11059 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11060 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11061 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11062 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11063 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11064 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11065 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11066 | NULL, 0, NULL, 0); |
| 11067 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11068 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11069 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11070 | &hanging_non_alternate_protocol_socket); |
| 11071 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11072 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11073 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11074 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11075 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11076 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11077 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11078 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11079 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11080 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11081 | |
| 11082 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11083 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11084 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11085 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11086 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 11087 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11088 | |
| 11089 | std::string response_data; |
| 11090 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11091 | EXPECT_EQ("hello world", response_data); |
| 11092 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11093 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11094 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11095 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11096 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11097 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11098 | |
| 11099 | response = trans->GetResponseInfo(); |
| 11100 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11101 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11102 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11103 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11104 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11105 | |
| 11106 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11107 | EXPECT_EQ("hello!", response_data); |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11108 | ASSERT_EQ(3u, capturing_proxy_resolver.resolved().size()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11109 | EXPECT_EQ("http://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11110 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11111 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11112 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11113 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11114 | LoadTimingInfo load_timing_info; |
| 11115 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11116 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11117 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11118 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11119 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11120 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11121 | UseAlternateProtocolForNpnSpdyWithExistingSpdySession) { |
rch | 3f4b845 | 2016-02-23 16:59:32 | [diff] [blame] | 11122 | session_deps_.parse_alternative_services = false; |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 11123 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11124 | |
| 11125 | HttpRequestInfo request; |
| 11126 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11127 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11128 | request.load_flags = 0; |
| 11129 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 11130 | std::string alternate_protocol_http_header = |
| 11131 | GetAlternateProtocolHttpHeader(); |
| 11132 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11133 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11134 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11135 | MockRead(alternate_protocol_http_header.c_str()), |
| 11136 | MockRead("\r\n"), |
| 11137 | MockRead("hello world"), |
| 11138 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11139 | }; |
| 11140 | |
| 11141 | StaticSocketDataProvider first_transaction( |
| 11142 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11143 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11144 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11145 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 11146 | ssl.SetNextProto(GetProtocol()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11147 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 11148 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11149 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11150 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11151 | scoped_ptr<SpdyFrame> req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 11152 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11153 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11154 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11155 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11156 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11157 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11158 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11159 | }; |
| 11160 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11161 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11162 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11163 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11164 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 11165 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11166 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11167 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11168 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11169 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11170 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11171 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11172 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11173 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11174 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11175 | |
| 11176 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11177 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11178 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11179 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11180 | |
| 11181 | std::string response_data; |
| 11182 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11183 | EXPECT_EQ("hello world", response_data); |
| 11184 | |
| 11185 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11186 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11187 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 11188 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11189 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11190 | CreateSecureSpdySession(session.get(), key, BoundNetLog()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 11191 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11192 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11193 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11194 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11195 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11196 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11197 | |
| 11198 | response = trans->GetResponseInfo(); |
| 11199 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11200 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11201 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11202 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11203 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11204 | |
| 11205 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11206 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11207 | } |
| 11208 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11209 | // GenerateAuthToken is a mighty big test. |
| 11210 | // It tests all permutation of GenerateAuthToken behavior: |
| 11211 | // - Synchronous and Asynchronous completion. |
| 11212 | // - OK or error on completion. |
| 11213 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 11214 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 11215 | // - Non-authenticating and authenticating backend. |
| 11216 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 11217 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11218 | // problems generating an auth token for an authenticating proxy, we don't |
| 11219 | // need to test all permutations of the backend server). |
| 11220 | // |
| 11221 | // The test proceeds by going over each of the configuration cases, and |
| 11222 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 11223 | // specifies both the configuration for the test as well as the expectations |
| 11224 | // for the results. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11225 | TEST_P(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11226 | static const char kServer[] = "http://www.example.com"; |
| 11227 | static const char kSecureServer[] = "https://www.example.com"; |
| 11228 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11229 | const int kAuthErr = ERR_INVALID_AUTH_CREDENTIALS; |
| 11230 | |
| 11231 | enum AuthTiming { |
| 11232 | AUTH_NONE, |
| 11233 | AUTH_SYNC, |
| 11234 | AUTH_ASYNC, |
| 11235 | }; |
| 11236 | |
| 11237 | const MockWrite kGet( |
| 11238 | "GET / HTTP/1.1\r\n" |
| 11239 | "Host: www.example.com\r\n" |
| 11240 | "Connection: keep-alive\r\n\r\n"); |
| 11241 | const MockWrite kGetProxy( |
| 11242 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11243 | "Host: www.example.com\r\n" |
| 11244 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11245 | const MockWrite kGetAuth( |
| 11246 | "GET / HTTP/1.1\r\n" |
| 11247 | "Host: www.example.com\r\n" |
| 11248 | "Connection: keep-alive\r\n" |
| 11249 | "Authorization: auth_token\r\n\r\n"); |
| 11250 | const MockWrite kGetProxyAuth( |
| 11251 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11252 | "Host: www.example.com\r\n" |
| 11253 | "Proxy-Connection: keep-alive\r\n" |
| 11254 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11255 | const MockWrite kGetAuthThroughProxy( |
| 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 | "Authorization: auth_token\r\n\r\n"); |
| 11260 | const MockWrite kGetAuthWithProxyAuth( |
| 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 | "Proxy-Authorization: auth_token\r\n" |
| 11265 | "Authorization: auth_token\r\n\r\n"); |
| 11266 | const MockWrite kConnect( |
| 11267 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11268 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11269 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11270 | const MockWrite kConnectProxyAuth( |
| 11271 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11272 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11273 | "Proxy-Connection: keep-alive\r\n" |
| 11274 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11275 | |
| 11276 | const MockRead kSuccess( |
| 11277 | "HTTP/1.1 200 OK\r\n" |
| 11278 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11279 | "Content-Length: 3\r\n\r\n" |
| 11280 | "Yes"); |
| 11281 | const MockRead kFailure( |
| 11282 | "Should not be called."); |
| 11283 | const MockRead kServerChallenge( |
| 11284 | "HTTP/1.1 401 Unauthorized\r\n" |
| 11285 | "WWW-Authenticate: Mock realm=server\r\n" |
| 11286 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11287 | "Content-Length: 14\r\n\r\n" |
| 11288 | "Unauthorized\r\n"); |
| 11289 | const MockRead kProxyChallenge( |
| 11290 | "HTTP/1.1 407 Unauthorized\r\n" |
| 11291 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 11292 | "Proxy-Connection: close\r\n" |
| 11293 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11294 | "Content-Length: 14\r\n\r\n" |
| 11295 | "Unauthorized\r\n"); |
| 11296 | const MockRead kProxyConnected( |
| 11297 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 11298 | |
| 11299 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 11300 | // no constructors, but the C++ compiler on Windows warns about |
| 11301 | // unspecified data in compound literals. So, moved to using constructors, |
| 11302 | // and TestRound's created with the default constructor should not be used. |
| 11303 | struct TestRound { |
| 11304 | TestRound() |
| 11305 | : expected_rv(ERR_UNEXPECTED), |
| 11306 | extra_write(NULL), |
| 11307 | extra_read(NULL) { |
| 11308 | } |
| 11309 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11310 | int expected_rv_arg) |
| 11311 | : write(write_arg), |
| 11312 | read(read_arg), |
| 11313 | expected_rv(expected_rv_arg), |
| 11314 | extra_write(NULL), |
| 11315 | extra_read(NULL) { |
| 11316 | } |
| 11317 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11318 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 11319 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11320 | : write(write_arg), |
| 11321 | read(read_arg), |
| 11322 | expected_rv(expected_rv_arg), |
| 11323 | extra_write(extra_write_arg), |
| 11324 | extra_read(extra_read_arg) { |
| 11325 | } |
| 11326 | MockWrite write; |
| 11327 | MockRead read; |
| 11328 | int expected_rv; |
| 11329 | const MockWrite* extra_write; |
| 11330 | const MockRead* extra_read; |
| 11331 | }; |
| 11332 | |
| 11333 | static const int kNoSSL = 500; |
| 11334 | |
| 11335 | struct TestConfig { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11336 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11337 | AuthTiming proxy_auth_timing; |
| 11338 | int proxy_auth_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11339 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11340 | AuthTiming server_auth_timing; |
| 11341 | int server_auth_rv; |
| 11342 | int num_auth_rounds; |
| 11343 | int first_ssl_round; |
| 11344 | TestRound rounds[3]; |
| 11345 | } test_configs[] = { |
| 11346 | // Non-authenticating HTTP server with a direct connection. |
| 11347 | { NULL, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 11348 | { TestRound(kGet, kSuccess, OK)}}, |
| 11349 | // Authenticating HTTP server with a direct connection. |
| 11350 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 11351 | { TestRound(kGet, kServerChallenge, OK), |
| 11352 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11353 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 11354 | { TestRound(kGet, kServerChallenge, OK), |
| 11355 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11356 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 11357 | { TestRound(kGet, kServerChallenge, OK), |
| 11358 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11359 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 11360 | { TestRound(kGet, kServerChallenge, OK), |
| 11361 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11362 | // Non-authenticating HTTP server through a non-authenticating proxy. |
| 11363 | { kProxy, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 11364 | { TestRound(kGetProxy, kSuccess, OK)}}, |
| 11365 | // Authenticating HTTP server through a non-authenticating proxy. |
| 11366 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 11367 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 11368 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 11369 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 11370 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 11371 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 11372 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 11373 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 11374 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 11375 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 11376 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 11377 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 11378 | // Non-authenticating HTTP server through an authenticating proxy. |
| 11379 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11380 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11381 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 11382 | { kProxy, AUTH_SYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11383 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11384 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 11385 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11386 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11387 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 11388 | { kProxy, AUTH_ASYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11389 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11390 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 11391 | // Authenticating HTTP server through an authenticating proxy. |
| 11392 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 11393 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11394 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11395 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11396 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 11397 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11398 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11399 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11400 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 11401 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11402 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11403 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11404 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 11405 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11406 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11407 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11408 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 11409 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11410 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11411 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11412 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 11413 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11414 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11415 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11416 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 11417 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11418 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11419 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11420 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 11421 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11422 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11423 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11424 | // Non-authenticating HTTPS server with a direct connection. |
| 11425 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 11426 | { TestRound(kGet, kSuccess, OK)}}, |
| 11427 | // Authenticating HTTPS server with a direct connection. |
| 11428 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 11429 | { TestRound(kGet, kServerChallenge, OK), |
| 11430 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11431 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 11432 | { TestRound(kGet, kServerChallenge, OK), |
| 11433 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11434 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 11435 | { TestRound(kGet, kServerChallenge, OK), |
| 11436 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11437 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 11438 | { TestRound(kGet, kServerChallenge, OK), |
| 11439 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11440 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
| 11441 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 11442 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11443 | // Authenticating HTTPS server through a non-authenticating proxy. |
| 11444 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 11445 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11446 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11447 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 11448 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11449 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11450 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 11451 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11452 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11453 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 11454 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11455 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11456 | // Non-Authenticating HTTPS server through an authenticating proxy. |
| 11457 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 11458 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11459 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11460 | { kProxy, AUTH_SYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11461 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11462 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 11463 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 11464 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11465 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11466 | { kProxy, AUTH_ASYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11467 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11468 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 11469 | // Authenticating HTTPS server through an authenticating proxy. |
| 11470 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 11471 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11472 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11473 | &kGet, &kServerChallenge), |
| 11474 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11475 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 11476 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11477 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11478 | &kGet, &kServerChallenge), |
| 11479 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11480 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 11481 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11482 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11483 | &kGet, &kServerChallenge), |
| 11484 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11485 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 11486 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11487 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11488 | &kGet, &kServerChallenge), |
| 11489 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11490 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 11491 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11492 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11493 | &kGet, &kServerChallenge), |
| 11494 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11495 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 11496 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11497 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11498 | &kGet, &kServerChallenge), |
| 11499 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11500 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 11501 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11502 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11503 | &kGet, &kServerChallenge), |
| 11504 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11505 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 11506 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11507 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11508 | &kGet, &kServerChallenge), |
| 11509 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11510 | }; |
| 11511 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 11512 | for (size_t i = 0; i < arraysize(test_configs); ++i) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11513 | HttpAuthHandlerMock::Factory* auth_factory( |
| 11514 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11515 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11516 | const TestConfig& test_config = test_configs[i]; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 11517 | |
| 11518 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11519 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11520 | for (int n = 0; n < 2; n++) { |
| 11521 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 11522 | std::string auth_challenge = "Mock realm=proxy"; |
| 11523 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 11524 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 11525 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11526 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
| 11527 | origin, BoundNetLog()); |
| 11528 | auth_handler->SetGenerateExpectation( |
| 11529 | test_config.proxy_auth_timing == AUTH_ASYNC, |
| 11530 | test_config.proxy_auth_rv); |
| 11531 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 11532 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11533 | } |
| 11534 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 11535 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11536 | std::string auth_challenge = "Mock realm=server"; |
| 11537 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 11538 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 11539 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11540 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 11541 | origin, BoundNetLog()); |
| 11542 | auth_handler->SetGenerateExpectation( |
| 11543 | test_config.server_auth_timing == AUTH_ASYNC, |
| 11544 | test_config.server_auth_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11545 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11546 | } |
| 11547 | if (test_config.proxy_url) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11548 | session_deps_.proxy_service = |
| 11549 | ProxyService::CreateFixed(test_config.proxy_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11550 | } else { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11551 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11552 | } |
| 11553 | |
| 11554 | HttpRequestInfo request; |
| 11555 | request.method = "GET"; |
| 11556 | request.url = GURL(test_config.server_url); |
| 11557 | request.load_flags = 0; |
| 11558 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11559 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11560 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11561 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 11562 | |
| 11563 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 11564 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11565 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 11566 | const TestRound& read_write_round = test_config.rounds[round]; |
| 11567 | |
| 11568 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11569 | mock_reads.back().push_back(read_write_round.read); |
| 11570 | mock_writes.back().push_back(read_write_round.write); |
| 11571 | |
| 11572 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 11573 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 11574 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11575 | mock_reads.push_back(std::vector<MockRead>()); |
| 11576 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11577 | } |
| 11578 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11579 | if (read_write_round.extra_read) { |
| 11580 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11581 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11582 | if (read_write_round.extra_write) { |
| 11583 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 11584 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11585 | |
| 11586 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11587 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11588 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11589 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11590 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11591 | |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 11592 | std::vector<scoped_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11593 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 11594 | data_providers.push_back(make_scoped_ptr(new StaticSocketDataProvider( |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 11595 | mock_reads[i].data(), mock_reads[i].size(), mock_writes[i].data(), |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 11596 | mock_writes[i].size()))); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11597 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 11598 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11599 | } |
| 11600 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11601 | // Transaction must be created after DataProviders, so it's destroyed before |
| 11602 | // they are as well. |
| 11603 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11604 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11605 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 11606 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11607 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11608 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11609 | int rv; |
| 11610 | if (round == 0) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11611 | rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11612 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11613 | rv = trans.RestartWithAuth( |
| 11614 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11615 | } |
| 11616 | if (rv == ERR_IO_PENDING) |
| 11617 | rv = callback.WaitForResult(); |
| 11618 | |
| 11619 | // Compare results with expected data. |
| 11620 | EXPECT_EQ(read_write_round.expected_rv, rv); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11621 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 11622 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11623 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 11624 | continue; |
| 11625 | } |
| 11626 | if (round + 1 < test_config.num_auth_rounds) { |
| 11627 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 11628 | } else { |
| 11629 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 11630 | } |
| 11631 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 11632 | } |
| 11633 | } |
| 11634 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11635 | TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11636 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11637 | HttpAuthHandlerMock::Factory* auth_factory( |
| 11638 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11639 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11640 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11641 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 11642 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11643 | |
| 11644 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 11645 | auth_handler->set_connection_based(true); |
| 11646 | std::string auth_challenge = "Mock realm=server"; |
| 11647 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 11648 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 11649 | auth_challenge.end()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11650 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 11651 | origin, BoundNetLog()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11652 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11653 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11654 | int rv = OK; |
| 11655 | const HttpResponseInfo* response = NULL; |
| 11656 | HttpRequestInfo request; |
| 11657 | request.method = "GET"; |
| 11658 | request.url = origin; |
| 11659 | request.load_flags = 0; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11660 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11661 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11662 | |
| 11663 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 11664 | // to validate that the TCP socket is not released to the pool between |
| 11665 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11666 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11667 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11668 | 50, // Max sockets for pool |
| 11669 | 1, // Max sockets per group |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11670 | session_deps_.host_resolver.get(), |
| 11671 | session_deps_.socket_factory.get(), |
| 11672 | session_deps_.net_log); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 11673 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 11674 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 11675 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11676 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11677 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11678 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11679 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11680 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11681 | |
| 11682 | const MockWrite kGet( |
| 11683 | "GET / HTTP/1.1\r\n" |
| 11684 | "Host: www.example.com\r\n" |
| 11685 | "Connection: keep-alive\r\n\r\n"); |
| 11686 | const MockWrite kGetAuth( |
| 11687 | "GET / HTTP/1.1\r\n" |
| 11688 | "Host: www.example.com\r\n" |
| 11689 | "Connection: keep-alive\r\n" |
| 11690 | "Authorization: auth_token\r\n\r\n"); |
| 11691 | |
| 11692 | const MockRead kServerChallenge( |
| 11693 | "HTTP/1.1 401 Unauthorized\r\n" |
| 11694 | "WWW-Authenticate: Mock realm=server\r\n" |
| 11695 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11696 | "Content-Length: 14\r\n\r\n" |
| 11697 | "Unauthorized\r\n"); |
| 11698 | const MockRead kSuccess( |
| 11699 | "HTTP/1.1 200 OK\r\n" |
| 11700 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11701 | "Content-Length: 3\r\n\r\n" |
| 11702 | "Yes"); |
| 11703 | |
| 11704 | MockWrite writes[] = { |
| 11705 | // First round |
| 11706 | kGet, |
| 11707 | // Second round |
| 11708 | kGetAuth, |
| 11709 | // Third round |
| 11710 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11711 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11712 | kGetAuth, |
| 11713 | // Competing request |
| 11714 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11715 | }; |
| 11716 | MockRead reads[] = { |
| 11717 | // First round |
| 11718 | kServerChallenge, |
| 11719 | // Second round |
| 11720 | kServerChallenge, |
| 11721 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11722 | kServerChallenge, |
| 11723 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11724 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11725 | // Competing response |
| 11726 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11727 | }; |
| 11728 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 11729 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11730 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11731 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11732 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11733 | |
| 11734 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11735 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11736 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11737 | if (rv == ERR_IO_PENDING) |
| 11738 | rv = callback.WaitForResult(); |
| 11739 | EXPECT_EQ(OK, rv); |
| 11740 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11741 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11742 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11743 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11744 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11745 | // In between rounds, another request comes in for the same domain. |
| 11746 | // It should not be able to grab the TCP socket that trans has already |
| 11747 | // claimed. |
| 11748 | scoped_ptr<HttpTransaction> trans_compete( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11749 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11750 | TestCompletionCallback callback_compete; |
| 11751 | rv = trans_compete->Start( |
| 11752 | &request, callback_compete.callback(), BoundNetLog()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11753 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11754 | // callback_compete.WaitForResult at this point would stall forever, |
| 11755 | // since the HttpNetworkTransaction does not release the request back to |
| 11756 | // the pool until after authentication completes. |
| 11757 | |
| 11758 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11759 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11760 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11761 | if (rv == ERR_IO_PENDING) |
| 11762 | rv = callback.WaitForResult(); |
| 11763 | EXPECT_EQ(OK, rv); |
| 11764 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11765 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11766 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11767 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11768 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11769 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11770 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11771 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11772 | if (rv == ERR_IO_PENDING) |
| 11773 | rv = callback.WaitForResult(); |
| 11774 | EXPECT_EQ(OK, rv); |
| 11775 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11776 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11777 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11778 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11779 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11780 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11781 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11782 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11783 | if (rv == ERR_IO_PENDING) |
| 11784 | rv = callback.WaitForResult(); |
| 11785 | EXPECT_EQ(OK, rv); |
| 11786 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11787 | ASSERT_TRUE(response != NULL); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11788 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11789 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11790 | |
| 11791 | // Read the body since the fourth round was successful. This will also |
| 11792 | // release the socket back to the pool. |
| 11793 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11794 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11795 | if (rv == ERR_IO_PENDING) |
| 11796 | rv = callback.WaitForResult(); |
| 11797 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11798 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11799 | EXPECT_EQ(0, rv); |
| 11800 | // There are still 0 idle sockets, since the trans_compete transaction |
| 11801 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11802 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11803 | |
| 11804 | // The competing request can now finish. Wait for the headers and then |
| 11805 | // read the body. |
| 11806 | rv = callback_compete.WaitForResult(); |
| 11807 | EXPECT_EQ(OK, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11808 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11809 | if (rv == ERR_IO_PENDING) |
| 11810 | rv = callback.WaitForResult(); |
| 11811 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11812 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11813 | EXPECT_EQ(0, rv); |
| 11814 | |
| 11815 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11816 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11817 | } |
| 11818 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11819 | // This tests the case that a request is issued via http instead of spdy after |
| 11820 | // npn is negotiated. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11821 | TEST_P(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 11822 | session_deps_.parse_alternative_services = true; |
| 11823 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11824 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11825 | HttpRequestInfo request; |
| 11826 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11827 | request.url = GURL("https://www.example.org/"); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11828 | request.load_flags = 0; |
| 11829 | |
| 11830 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11831 | MockWrite( |
| 11832 | "GET / HTTP/1.1\r\n" |
| 11833 | "Host: www.example.org\r\n" |
| 11834 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11835 | }; |
| 11836 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 11837 | std::string alternate_protocol_http_header = |
| 11838 | GetAlternateProtocolHttpHeader(); |
| 11839 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11840 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11841 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11842 | MockRead(alternate_protocol_http_header.c_str()), |
| 11843 | MockRead("\r\n"), |
| 11844 | MockRead("hello world"), |
| 11845 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11846 | }; |
| 11847 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11848 | SSLSocketDataProvider ssl(ASYNC, OK); |
davidben | 6974bf7 | 2015-04-27 17:52:48 | [diff] [blame] | 11849 | ssl.SetNextProto(kProtoHTTP11); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11850 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11851 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11852 | |
| 11853 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 11854 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11855 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11856 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11857 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11858 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11859 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11860 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11861 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11862 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11863 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11864 | |
| 11865 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11866 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11867 | |
| 11868 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11869 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11870 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11871 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11872 | |
| 11873 | std::string response_data; |
| 11874 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11875 | EXPECT_EQ("hello world", response_data); |
| 11876 | |
| 11877 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 11878 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11879 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11880 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11881 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 11882 | // immediate server closing of the socket. |
| 11883 | // Regression test for https://crbug.com/46369. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11884 | TEST_P(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 11885 | session_deps_.parse_alternative_services = true; |
| 11886 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11887 | |
| 11888 | HttpRequestInfo request; |
| 11889 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11890 | request.url = GURL("https://www.example.org/"); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11891 | request.load_flags = 0; |
| 11892 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11893 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 11894 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11895 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11896 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11897 | scoped_ptr<SpdyFrame> req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 11898 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11899 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11900 | |
| 11901 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11902 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11903 | }; |
| 11904 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11905 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11906 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11907 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11908 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11909 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11910 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11911 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11912 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11913 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11914 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11915 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11916 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11917 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11918 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 11919 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11920 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 11921 | // it gets it. This is needed since the auth handler may get destroyed |
| 11922 | // before we get a chance to query it. |
| 11923 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 11924 | public: |
| 11925 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 11926 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11927 | ~UrlRecordingHttpAuthHandlerMock() override {} |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11928 | |
| 11929 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11930 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 11931 | const HttpRequestInfo* request, |
| 11932 | const CompletionCallback& callback, |
| 11933 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11934 | *url_ = request->url; |
| 11935 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 11936 | credentials, request, callback, auth_token); |
| 11937 | } |
| 11938 | |
| 11939 | private: |
| 11940 | GURL* url_; |
| 11941 | }; |
| 11942 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11943 | // This test ensures that the URL passed into the proxy is upgraded to https |
| 11944 | // when doing an Alternate Protocol upgrade. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11945 | TEST_P(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) { |
rch | 3f4b845 | 2016-02-23 16:59:32 | [diff] [blame] | 11946 | session_deps_.parse_alternative_services = false; |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 11947 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11948 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11949 | session_deps_.proxy_service = |
| 11950 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11951 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11952 | session_deps_.net_log = &net_log; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11953 | GURL request_url; |
| 11954 | { |
| 11955 | HttpAuthHandlerMock::Factory* auth_factory = |
| 11956 | new HttpAuthHandlerMock::Factory(); |
| 11957 | UrlRecordingHttpAuthHandlerMock* auth_handler = |
| 11958 | new UrlRecordingHttpAuthHandlerMock(&request_url); |
| 11959 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 11960 | auth_factory->set_do_init_from_challenge(true); |
| 11961 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
| 11962 | } |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11963 | |
| 11964 | HttpRequestInfo request; |
| 11965 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11966 | request.url = GURL("http://www.example.org"); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11967 | request.load_flags = 0; |
| 11968 | |
| 11969 | // First round goes unauthenticated through the proxy. |
| 11970 | MockWrite data_writes_1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11971 | MockWrite( |
| 11972 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 11973 | "Host: www.example.org\r\n" |
| 11974 | "Proxy-Connection: keep-alive\r\n" |
| 11975 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11976 | }; |
| 11977 | MockRead data_reads_1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11978 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 11979 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11980 | MockRead("Alternate-Protocol: 443:"), |
| 11981 | MockRead(GetAlternateProtocolFromParam()), |
| 11982 | MockRead("\r\n"), |
| 11983 | MockRead("Proxy-Connection: close\r\n"), |
| 11984 | MockRead("\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11985 | }; |
| 11986 | StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1), |
| 11987 | data_writes_1, arraysize(data_writes_1)); |
| 11988 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11989 | // Second round tries to tunnel to www.example.org due to the |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11990 | // Alternate-Protocol announcement in the first round. It fails due |
| 11991 | // to a proxy authentication challenge. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11992 | // After the failure, a tunnel is established to www.example.org using |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11993 | // Proxy-Authorization headers. There is then a SPDY request round. |
| 11994 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 11995 | // NOTE: Despite the "Proxy-Connection: Close", these are done on the |
| 11996 | // same MockTCPClientSocket since the underlying HttpNetworkClientSocket |
| 11997 | // does a Disconnect and Connect on the same socket, rather than trying |
| 11998 | // to obtain a new one. |
| 11999 | // |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 12000 | // NOTE: Originally, the proxy response to the second CONNECT request |
| 12001 | // simply returned another 407 so the unit test could skip the SSL connection |
| 12002 | // establishment and SPDY framing issues. Alas, the |
| 12003 | // retry-http-when-alternate-protocol fails logic kicks in, which was more |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12004 | // complicated to set up expectations for than the SPDY session. |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 12005 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12006 | scoped_ptr<SpdyFrame> req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12007 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12008 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12009 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12010 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 12011 | MockWrite data_writes_2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12012 | // First connection attempt without Proxy-Authorization. |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12013 | MockWrite(ASYNC, 0, |
| 12014 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12015 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12016 | "Proxy-Connection: keep-alive\r\n" |
| 12017 | "\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 12018 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12019 | // Second connection attempt with Proxy-Authorization. |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12020 | MockWrite(ASYNC, 2, |
| 12021 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12022 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12023 | "Proxy-Connection: keep-alive\r\n" |
| 12024 | "Proxy-Authorization: auth_token\r\n" |
| 12025 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12026 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12027 | // SPDY request |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12028 | CreateMockWrite(*req, 4), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12029 | }; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 12030 | MockRead data_reads_2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12031 | // First connection attempt fails |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 12032 | MockRead(ASYNC, 1, |
| 12033 | "HTTP/1.1 407 Unauthorized\r\n" |
| 12034 | "Proxy-Authenticate: Mock\r\n" |
| 12035 | "Content-Length: 0\r\n" |
| 12036 | "Proxy-Connection: keep-alive\r\n" |
| 12037 | "\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 12038 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12039 | // Second connection attempt passes |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 12040 | MockRead(ASYNC, 3, "HTTP/1.1 200 Connected\r\n\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 12041 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12042 | // SPDY response |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 12043 | CreateMockRead(*resp.get(), 5), CreateMockRead(*data.get(), 6), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12044 | MockRead(ASYNC, 0, 0, 7), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 12045 | }; |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12046 | SequencedSocketData data_2(data_reads_2, arraysize(data_reads_2), |
| 12047 | data_writes_2, arraysize(data_writes_2)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12048 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12049 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12050 | ssl.SetNextProto(GetProtocol()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12051 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 12052 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12053 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12054 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12055 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 12056 | NULL, 0, NULL, 0); |
| 12057 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 12058 | never_finishing_connect); |
| 12059 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12060 | session_deps_.socket_factory->AddSocketDataProvider(&data_1); |
| 12061 | session_deps_.socket_factory->AddSocketDataProvider(&data_2); |
| 12062 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12063 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12064 | &hanging_non_alternate_protocol_socket); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12065 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12066 | |
| 12067 | // First round should work and provide the Alternate-Protocol state. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12068 | TestCompletionCallback callback_1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12069 | scoped_ptr<HttpTransaction> trans_1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12070 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12071 | int rv = trans_1->Start(&request, callback_1.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12072 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12073 | EXPECT_EQ(OK, callback_1.WaitForResult()); |
| 12074 | |
| 12075 | // Second round should attempt a tunnel connect and get an auth challenge. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12076 | TestCompletionCallback callback_2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12077 | scoped_ptr<HttpTransaction> trans_2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12078 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12079 | rv = trans_2->Start(&request, callback_2.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12080 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12081 | EXPECT_EQ(OK, callback_2.WaitForResult()); |
| 12082 | const HttpResponseInfo* response = trans_2->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 12083 | ASSERT_TRUE(response != NULL); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12084 | ASSERT_FALSE(response->auth_challenge.get() == NULL); |
| 12085 | |
| 12086 | // Restart with auth. Tunnel should work and response received. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12087 | TestCompletionCallback callback_3; |
| 12088 | rv = trans_2->RestartWithAuth( |
| 12089 | AuthCredentials(kFoo, kBar), callback_3.callback()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12090 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12091 | EXPECT_EQ(OK, callback_3.WaitForResult()); |
| 12092 | |
| 12093 | // After all that work, these two lines (or actually, just the scheme) are |
| 12094 | // what this test is all about. Make sure it happens correctly. |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12095 | EXPECT_EQ("https", request_url.scheme()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12096 | EXPECT_EQ("www.example.org", request_url.host()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12097 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12098 | LoadTimingInfo load_timing_info; |
| 12099 | EXPECT_TRUE(trans_2->GetLoadTimingInfo(&load_timing_info)); |
| 12100 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12101 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12102 | } |
| 12103 | |
| 12104 | // Test that if we cancel the transaction as the connection is completing, that |
| 12105 | // everything tears down correctly. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12106 | TEST_P(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12107 | // Setup everything about the connection to complete synchronously, so that |
| 12108 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 12109 | // for is the callback from the HttpStreamRequest. |
| 12110 | // Then cancel the transaction. |
| 12111 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12112 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12113 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12114 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 12115 | MockRead(SYNCHRONOUS, "hello world"), |
| 12116 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12117 | }; |
| 12118 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12119 | HttpRequestInfo request; |
| 12120 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12121 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12122 | request.load_flags = 0; |
| 12123 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12124 | session_deps_.host_resolver->set_synchronous_mode(true); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12125 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12126 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12127 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12128 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12129 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 12130 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12131 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12132 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12133 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12134 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12135 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12136 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12137 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12138 | trans.reset(); // Cancel the transaction here. |
| 12139 | |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12140 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12141 | } |
| 12142 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12143 | // Test that if a transaction is cancelled after receiving the headers, the |
| 12144 | // stream is drained properly and added back to the socket pool. The main |
| 12145 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 12146 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 12147 | // deleted. |
| 12148 | // See http://crbug.com/368418 |
| 12149 | TEST_P(HttpNetworkTransactionTest, CancelAfterHeaders) { |
| 12150 | MockRead data_reads[] = { |
| 12151 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 12152 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 12153 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 12154 | MockRead(ASYNC, "1"), |
| 12155 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 12156 | // HttpNetworkTransaction has been deleted. |
| 12157 | MockRead(ASYNC, "2"), |
| 12158 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 12159 | }; |
| 12160 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 12161 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12162 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12163 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12164 | |
| 12165 | { |
| 12166 | HttpRequestInfo request; |
| 12167 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12168 | request.url = GURL("http://www.example.org/"); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12169 | request.load_flags = 0; |
| 12170 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12171 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12172 | TestCompletionCallback callback; |
| 12173 | |
| 12174 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
| 12175 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12176 | callback.WaitForResult(); |
| 12177 | |
| 12178 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 12179 | ASSERT_TRUE(response != NULL); |
| 12180 | EXPECT_TRUE(response->headers.get() != NULL); |
| 12181 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12182 | |
| 12183 | // The transaction and HttpRequestInfo are deleted. |
| 12184 | } |
| 12185 | |
| 12186 | // Let the HttpResponseBodyDrainer drain the socket. |
| 12187 | base::MessageLoop::current()->RunUntilIdle(); |
| 12188 | |
| 12189 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12190 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12191 | } |
| 12192 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12193 | // Test a basic GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12194 | TEST_P(HttpNetworkTransactionTest, ProxyGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12195 | session_deps_.proxy_service = |
| 12196 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12197 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12198 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12199 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12200 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12201 | HttpRequestInfo request; |
| 12202 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12203 | request.url = GURL("http://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12204 | |
| 12205 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12206 | MockWrite( |
| 12207 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 12208 | "Host: www.example.org\r\n" |
| 12209 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12210 | }; |
| 12211 | |
| 12212 | MockRead data_reads1[] = { |
| 12213 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12214 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12215 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12216 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12217 | }; |
| 12218 | |
| 12219 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12220 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12221 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12222 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12223 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12224 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12225 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12226 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 12227 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 12228 | trans->SetBeforeProxyHeadersSentCallback( |
| 12229 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 12230 | base::Unretained(&proxy_headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12231 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12232 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12233 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12234 | |
| 12235 | rv = callback1.WaitForResult(); |
| 12236 | EXPECT_EQ(OK, rv); |
| 12237 | |
| 12238 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 12239 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12240 | |
| 12241 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12242 | EXPECT_EQ(200, response->headers->response_code()); |
| 12243 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12244 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 12245 | EXPECT_TRUE( |
| 12246 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 12247 | EXPECT_TRUE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
| 12248 | EXPECT_EQ("myproxy:70", proxy_headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12249 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12250 | |
| 12251 | LoadTimingInfo load_timing_info; |
| 12252 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 12253 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12254 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12255 | } |
| 12256 | |
| 12257 | // Test a basic HTTPS GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12258 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12259 | session_deps_.proxy_service = |
| 12260 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12261 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12262 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12263 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12264 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12265 | HttpRequestInfo request; |
| 12266 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12267 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12268 | |
| 12269 | // Since we have proxy, should try to establish tunnel. |
| 12270 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12271 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12272 | "Host: www.example.org:443\r\n" |
| 12273 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12274 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12275 | MockWrite("GET / HTTP/1.1\r\n" |
| 12276 | "Host: www.example.org\r\n" |
| 12277 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12278 | }; |
| 12279 | |
| 12280 | MockRead data_reads1[] = { |
| 12281 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 12282 | |
| 12283 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12284 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12285 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12286 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12287 | }; |
| 12288 | |
| 12289 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12290 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12291 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12292 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12293 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12294 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12295 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12296 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12297 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12298 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12299 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12300 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12301 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12302 | |
| 12303 | rv = callback1.WaitForResult(); |
| 12304 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 12305 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12306 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12307 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12308 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12309 | NetLog::PHASE_NONE); |
| 12310 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12311 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12312 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12313 | NetLog::PHASE_NONE); |
| 12314 | |
| 12315 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 12316 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12317 | |
| 12318 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12319 | EXPECT_EQ(200, response->headers->response_code()); |
| 12320 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12321 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 12322 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 12323 | EXPECT_TRUE( |
| 12324 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12325 | |
| 12326 | LoadTimingInfo load_timing_info; |
| 12327 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 12328 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12329 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12330 | } |
| 12331 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12332 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 12333 | // literal host. |
| 12334 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
| 12335 | session_deps_.proxy_service = |
| 12336 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 12337 | BoundTestNetLog log; |
| 12338 | session_deps_.net_log = log.bound().net_log(); |
| 12339 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12340 | |
| 12341 | HttpRequestInfo request; |
| 12342 | request.method = "GET"; |
| 12343 | request.url = GURL("https://[::1]:443/"); |
| 12344 | |
| 12345 | // Since we have proxy, should try to establish tunnel. |
| 12346 | MockWrite data_writes1[] = { |
| 12347 | MockWrite("CONNECT [::1]:443 HTTP/1.1\r\n" |
| 12348 | "Host: [::1]:443\r\n" |
| 12349 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 12350 | |
| 12351 | MockWrite("GET / HTTP/1.1\r\n" |
| 12352 | "Host: [::1]\r\n" |
| 12353 | "Connection: keep-alive\r\n\r\n"), |
| 12354 | }; |
| 12355 | |
| 12356 | MockRead data_reads1[] = { |
| 12357 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 12358 | |
| 12359 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12360 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12361 | MockRead("Content-Length: 100\r\n\r\n"), |
| 12362 | MockRead(SYNCHRONOUS, OK), |
| 12363 | }; |
| 12364 | |
| 12365 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12366 | data_writes1, arraysize(data_writes1)); |
| 12367 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 12368 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12369 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12370 | |
| 12371 | TestCompletionCallback callback1; |
| 12372 | |
| 12373 | scoped_ptr<HttpTransaction> trans( |
| 12374 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12375 | |
| 12376 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 12377 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12378 | |
| 12379 | rv = callback1.WaitForResult(); |
| 12380 | EXPECT_EQ(OK, rv); |
| 12381 | TestNetLogEntry::List entries; |
| 12382 | log.GetEntries(&entries); |
| 12383 | size_t pos = ExpectLogContainsSomewhere( |
| 12384 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 12385 | NetLog::PHASE_NONE); |
| 12386 | ExpectLogContainsSomewhere( |
| 12387 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12388 | NetLog::PHASE_NONE); |
| 12389 | |
| 12390 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 12391 | ASSERT_TRUE(response != NULL); |
| 12392 | |
| 12393 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12394 | EXPECT_EQ(200, response->headers->response_code()); |
| 12395 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12396 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 12397 | EXPECT_TRUE(response->was_fetched_via_proxy); |
| 12398 | EXPECT_TRUE( |
| 12399 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
| 12400 | |
| 12401 | LoadTimingInfo load_timing_info; |
| 12402 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 12403 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12404 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 12405 | } |
| 12406 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12407 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 12408 | // while establishing the tunnel. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12409 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12410 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12411 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12412 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12413 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12414 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12415 | HttpRequestInfo request; |
| 12416 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12417 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12418 | |
| 12419 | // Since we have proxy, should try to establish tunnel. |
| 12420 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12421 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12422 | "Host: www.example.org:443\r\n" |
| 12423 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12424 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12425 | MockWrite("GET / HTTP/1.1\r\n" |
| 12426 | "Host: www.example.org\r\n" |
| 12427 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12428 | }; |
| 12429 | |
| 12430 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12431 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12432 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12433 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12434 | }; |
| 12435 | |
| 12436 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12437 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12438 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12439 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12440 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12441 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12442 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12443 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12444 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12445 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12446 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12447 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12448 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12449 | |
| 12450 | rv = callback1.WaitForResult(); |
| 12451 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 12452 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12453 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12454 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12455 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12456 | NetLog::PHASE_NONE); |
| 12457 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12458 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12459 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12460 | NetLog::PHASE_NONE); |
| 12461 | } |
| 12462 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12463 | // Test for crbug.com/55424. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12464 | TEST_P(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12465 | scoped_ptr<SpdyFrame> req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12466 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12467 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12468 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12469 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12470 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12471 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12472 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12473 | }; |
| 12474 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12475 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12476 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12477 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12478 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12479 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12480 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12481 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12482 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12483 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12484 | |
| 12485 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12486 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12487 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 12488 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12489 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12490 | CreateInsecureSpdySession(session.get(), key, BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12491 | |
| 12492 | HttpRequestInfo request; |
| 12493 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12494 | request.url = GURL("https://www.example.org/"); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12495 | request.load_flags = 0; |
| 12496 | |
| 12497 | // This is the important line that marks this as a preconnect. |
| 12498 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 12499 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12500 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12501 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12502 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12503 | TestCompletionCallback callback; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12504 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12505 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12506 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12507 | } |
| 12508 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12509 | // Given a net error, cause that error to be returned from the first Write() |
| 12510 | // call and verify that the HttpTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12511 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12512 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12513 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12514 | request_info.url = GURL("https://www.example.com/"); |
| 12515 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12516 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12517 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12518 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12519 | MockWrite data_writes[] = { |
| 12520 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12521 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12522 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12523 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12524 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12525 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12526 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12527 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12528 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12529 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12530 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12531 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 12532 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12533 | rv = callback.WaitForResult(); |
| 12534 | ASSERT_EQ(error, rv); |
| 12535 | } |
| 12536 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12537 | TEST_P(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12538 | // Just check a grab bag of cert errors. |
| 12539 | static const int kErrors[] = { |
| 12540 | ERR_CERT_COMMON_NAME_INVALID, |
| 12541 | ERR_CERT_AUTHORITY_INVALID, |
| 12542 | ERR_CERT_DATE_INVALID, |
| 12543 | }; |
| 12544 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12545 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 12546 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12547 | } |
| 12548 | } |
| 12549 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12550 | // Ensure that a client certificate is removed from the SSL client auth |
| 12551 | // cache when: |
| 12552 | // 1) No proxy is involved. |
| 12553 | // 2) TLS False Start is disabled. |
| 12554 | // 3) The initial TLS handshake requests a client certificate. |
| 12555 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12556 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 12557 | ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12558 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12559 | request_info.url = GURL("https://www.example.com/"); |
| 12560 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12561 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12562 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12563 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12564 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12565 | |
| 12566 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 12567 | // CertificateRequest is received for the first time, the handshake will |
| 12568 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12569 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12570 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12571 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12572 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12573 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12574 | |
| 12575 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 12576 | // False Start is not being used, the result of the SSL handshake will be |
| 12577 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 12578 | // matches the result of a server sending a handshake_failure alert, |
| 12579 | // rather than a Finished message, because it requires a client |
| 12580 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12581 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12582 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12583 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12584 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12585 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12586 | |
| 12587 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 12588 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 12589 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 12590 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12591 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 12592 | // requiring a client certificate, this fallback handshake should also |
| 12593 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12594 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12595 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12596 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12597 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12598 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12599 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12600 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 12601 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 12602 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 12603 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12604 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 12605 | // requiring a client certificate, this fallback handshake should also |
| 12606 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12607 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12608 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12609 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12610 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12611 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12612 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12613 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12614 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12615 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12616 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12617 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12618 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12619 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 12620 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12621 | |
| 12622 | // Complete the SSL handshake, which should abort due to requiring a |
| 12623 | // client certificate. |
| 12624 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12625 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12626 | |
| 12627 | // Indicate that no certificate should be supplied. From the perspective |
| 12628 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 12629 | // certificate, so this is the same as supply a |
| 12630 | // legitimate-but-unacceptable certificate. |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12631 | rv = trans->RestartWithCertificate(NULL, NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12632 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12633 | |
| 12634 | // Ensure the certificate was added to the client auth cache before |
| 12635 | // allowing the connection to continue restarting. |
| 12636 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12637 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12638 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12639 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12640 | ASSERT_EQ(NULL, client_cert.get()); |
| 12641 | |
| 12642 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12643 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 12644 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12645 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12646 | ASSERT_EQ(ERR_SSL_PROTOCOL_ERROR, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12647 | |
| 12648 | // Ensure that the client certificate is removed from the cache on a |
| 12649 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12650 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12651 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12652 | } |
| 12653 | |
| 12654 | // Ensure that a client certificate is removed from the SSL client auth |
| 12655 | // cache when: |
| 12656 | // 1) No proxy is involved. |
| 12657 | // 2) TLS False Start is enabled. |
| 12658 | // 3) The initial TLS handshake requests a client certificate. |
| 12659 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12660 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 12661 | ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12662 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12663 | request_info.url = GURL("https://www.example.com/"); |
| 12664 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12665 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12666 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12667 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12668 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12669 | |
| 12670 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 12671 | // return successfully after reading up to the peer's Certificate message. |
| 12672 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 12673 | // enqueue application data to be sent in the same packet as the |
| 12674 | // ChangeCipherSpec and Finished messages. |
| 12675 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 12676 | // called, which expects to process the peer's ChangeCipherSpec and |
| 12677 | // Finished messages. If there was an error negotiating with the peer, |
| 12678 | // such as due to the peer requiring a client certificate when none was |
| 12679 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 12680 | // called. |
| 12681 | |
| 12682 | // Like the non-False Start case, when a client certificate is requested by |
| 12683 | // the peer, the handshake is aborted during the Connect() call. |
| 12684 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12685 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12686 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12687 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12688 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12689 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12690 | |
| 12691 | // When a client certificate is supplied, Connect() will not be aborted |
| 12692 | // when the peer requests the certificate. Instead, the handshake will |
| 12693 | // artificially succeed, allowing the caller to write the HTTP request to |
| 12694 | // the socket. The handshake messages are not processed until Read() is |
| 12695 | // called, which then detects that the handshake was aborted, due to the |
| 12696 | // peer sending a handshake_failure because it requires a client |
| 12697 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12698 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12699 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12700 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12701 | MockRead data2_reads[] = { |
| 12702 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12703 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12704 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12705 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12706 | |
| 12707 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12708 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 12709 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12710 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12711 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12712 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12713 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12714 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12715 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12716 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 12717 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12718 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12719 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12720 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12721 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12722 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12723 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 12724 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12725 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 12726 | ssl_data5.cert_request_info = cert_request.get(); |
| 12727 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12728 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 12729 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 12730 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12731 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12732 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12733 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12734 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12735 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12736 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12737 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 12738 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12739 | |
| 12740 | // Complete the SSL handshake, which should abort due to requiring a |
| 12741 | // client certificate. |
| 12742 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12743 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12744 | |
| 12745 | // Indicate that no certificate should be supplied. From the perspective |
| 12746 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 12747 | // certificate, so this is the same as supply a |
| 12748 | // legitimate-but-unacceptable certificate. |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12749 | rv = trans->RestartWithCertificate(NULL, NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12750 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12751 | |
| 12752 | // Ensure the certificate was added to the client auth cache before |
| 12753 | // allowing the connection to continue restarting. |
| 12754 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12755 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12756 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12757 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12758 | ASSERT_EQ(NULL, client_cert.get()); |
| 12759 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12760 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12761 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 12762 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12763 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12764 | ASSERT_EQ(ERR_SSL_PROTOCOL_ERROR, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12765 | |
| 12766 | // Ensure that the client certificate is removed from the cache on a |
| 12767 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12768 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12769 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12770 | } |
| 12771 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12772 | // Ensure that a client certificate is removed from the SSL client auth |
| 12773 | // cache when: |
| 12774 | // 1) An HTTPS proxy is involved. |
| 12775 | // 3) The HTTPS proxy requests a client certificate. |
| 12776 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 12777 | // proxy. |
| 12778 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 12779 | // then for connecting to an HTTP endpoint. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12780 | TEST_P(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12781 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12782 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12783 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12784 | |
| 12785 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12786 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12787 | |
| 12788 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 12789 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 12790 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 12791 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12792 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12793 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12794 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12795 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12796 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12797 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12798 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12799 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12800 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12801 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12802 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12803 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12804 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 12805 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12806 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12807 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12808 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12809 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12810 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12811 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12812 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12813 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12814 | requests[0].url = GURL("https://www.example.com/"); |
| 12815 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12816 | requests[0].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12817 | |
| 12818 | requests[1].url = GURL("http://www.example.com/"); |
| 12819 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12820 | requests[1].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12821 | |
| 12822 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12823 | session_deps_.socket_factory->ResetNextMockIndexes(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12824 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12825 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12826 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12827 | |
| 12828 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12829 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12830 | int rv = trans->Start(&requests[i], callback.callback(), BoundNetLog()); |
| 12831 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12832 | |
| 12833 | // Complete the SSL handshake, which should abort due to requiring a |
| 12834 | // client certificate. |
| 12835 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12836 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12837 | |
| 12838 | // Indicate that no certificate should be supplied. From the perspective |
| 12839 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 12840 | // certificate, so this is the same as supply a |
| 12841 | // legitimate-but-unacceptable certificate. |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12842 | rv = trans->RestartWithCertificate(NULL, NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12843 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12844 | |
| 12845 | // Ensure the certificate was added to the client auth cache before |
| 12846 | // allowing the connection to continue restarting. |
| 12847 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12848 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12849 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12850 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12851 | ASSERT_EQ(NULL, client_cert.get()); |
| 12852 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 12853 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12854 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12855 | HostPortPair("www.example.com", 443), &client_cert, |
| 12856 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12857 | |
| 12858 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 12859 | // then consume ssl_data3, which should also fail. The result code is |
| 12860 | // checked against what ssl_data3 should return. |
| 12861 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12862 | ASSERT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12863 | |
| 12864 | // Now that the new handshake has failed, ensure that the client |
| 12865 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12866 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12867 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12868 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12869 | HostPortPair("www.example.com", 443), &client_cert, |
| 12870 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12871 | } |
| 12872 | } |
| 12873 | |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 12874 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 12875 | session_deps_.parse_alternative_services = true; |
| 12876 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12877 | |
| 12878 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12879 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12880 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 12881 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 12882 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12883 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12884 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12885 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12886 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12887 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12888 | scoped_ptr<SpdyFrame> host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12889 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12890 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12891 | scoped_ptr<SpdyFrame> host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12892 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12893 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12894 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12895 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12896 | scoped_ptr<SpdyFrame> host1_resp( |
| 12897 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12898 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 12899 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12900 | scoped_ptr<SpdyFrame> host2_resp( |
| 12901 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12902 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 12903 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12904 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12905 | CreateMockRead(*host1_resp, 1), |
| 12906 | CreateMockRead(*host1_resp_body, 2), |
| 12907 | CreateMockRead(*host2_resp, 4), |
| 12908 | CreateMockRead(*host2_resp_body, 5), |
| 12909 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12910 | }; |
| 12911 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 12912 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12913 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12914 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 12915 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12916 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12917 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 12918 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12919 | HttpRequestInfo request1; |
| 12920 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12921 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12922 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12923 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12924 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12925 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12926 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12927 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12928 | |
| 12929 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 12930 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12931 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12932 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12933 | |
| 12934 | std::string response_data; |
| 12935 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 12936 | EXPECT_EQ("hello!", response_data); |
| 12937 | |
| 12938 | // Preload www.gmail.com into HostCache. |
| 12939 | HostPortPair host_port("www.gmail.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12940 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12941 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12942 | rv = session_deps_.host_resolver->Resolve(resolve_info, |
| 12943 | DEFAULT_PRIORITY, |
| 12944 | &ignored, |
| 12945 | callback.callback(), |
| 12946 | NULL, |
| 12947 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 12948 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12949 | rv = callback.WaitForResult(); |
| 12950 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12951 | |
| 12952 | HttpRequestInfo request2; |
| 12953 | request2.method = "GET"; |
| 12954 | request2.url = GURL("https://www.gmail.com/"); |
| 12955 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12956 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12957 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12958 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12959 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12960 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12961 | |
| 12962 | response = trans2.GetResponseInfo(); |
| 12963 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12964 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12965 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12966 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12967 | EXPECT_TRUE(response->was_npn_negotiated); |
| 12968 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 12969 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12970 | } |
| 12971 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12972 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 12973 | session_deps_.parse_alternative_services = true; |
| 12974 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12975 | |
| 12976 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12977 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12978 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12979 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 12980 | pool_peer.DisableDomainAuthenticationVerification(); |
| 12981 | |
| 12982 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12983 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12984 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12985 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12986 | scoped_ptr<SpdyFrame> host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12987 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12988 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12989 | scoped_ptr<SpdyFrame> host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12990 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12991 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12992 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12993 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12994 | scoped_ptr<SpdyFrame> host1_resp( |
| 12995 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12996 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 12997 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12998 | scoped_ptr<SpdyFrame> host2_resp( |
| 12999 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 13000 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 13001 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13002 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13003 | CreateMockRead(*host1_resp, 1), |
| 13004 | CreateMockRead(*host1_resp_body, 2), |
| 13005 | CreateMockRead(*host2_resp, 4), |
| 13006 | CreateMockRead(*host2_resp_body, 5), |
| 13007 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13008 | }; |
| 13009 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13010 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13011 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13012 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13013 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13014 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13015 | |
| 13016 | TestCompletionCallback callback; |
| 13017 | HttpRequestInfo request1; |
| 13018 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13019 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13020 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13021 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13022 | |
| 13023 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
| 13024 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13025 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 13026 | |
| 13027 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 13028 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13029 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13030 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13031 | |
| 13032 | std::string response_data; |
| 13033 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 13034 | EXPECT_EQ("hello!", response_data); |
| 13035 | |
| 13036 | HttpRequestInfo request2; |
| 13037 | request2.method = "GET"; |
| 13038 | request2.url = GURL("https://www.gmail.com/"); |
| 13039 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13040 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13041 | |
| 13042 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
| 13043 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13044 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 13045 | |
| 13046 | response = trans2.GetResponseInfo(); |
| 13047 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13048 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13049 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13050 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13051 | EXPECT_TRUE(response->was_npn_negotiated); |
| 13052 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 13053 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13054 | } |
| 13055 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13056 | class OneTimeCachingHostResolver : public HostResolver { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13057 | public: |
| 13058 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
| 13059 | : host_port_(host_port) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13060 | ~OneTimeCachingHostResolver() override {} |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13061 | |
| 13062 | RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); } |
| 13063 | |
| 13064 | // HostResolver methods: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13065 | int Resolve(const RequestInfo& info, |
| 13066 | RequestPriority priority, |
| 13067 | AddressList* addresses, |
| 13068 | const CompletionCallback& callback, |
| 13069 | RequestHandle* out_req, |
| 13070 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 13071 | return host_resolver_.Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 13072 | info, priority, addresses, callback, out_req, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 13073 | } |
| 13074 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13075 | int ResolveFromCache(const RequestInfo& info, |
| 13076 | AddressList* addresses, |
| 13077 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 13078 | int rv = host_resolver_.ResolveFromCache(info, addresses, net_log); |
| 13079 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
[email protected] | 98e1cd01 | 2011-11-08 15:33:09 | [diff] [blame] | 13080 | host_resolver_.GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13081 | return rv; |
| 13082 | } |
| 13083 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13084 | void CancelRequest(RequestHandle req) override { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13085 | host_resolver_.CancelRequest(req); |
| 13086 | } |
| 13087 | |
[email protected] | 46da33be | 2011-07-19 21:58:04 | [diff] [blame] | 13088 | MockCachingHostResolver* GetMockHostResolver() { |
| 13089 | return &host_resolver_; |
| 13090 | } |
| 13091 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13092 | private: |
| 13093 | MockCachingHostResolver host_resolver_; |
| 13094 | const HostPortPair host_port_; |
| 13095 | }; |
| 13096 | |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 13097 | TEST_P(HttpNetworkTransactionTest, |
| 13098 | UseIPConnectionPoolingWithHostCacheExpiration) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 13099 | session_deps_.parse_alternative_services = true; |
| 13100 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13101 | |
| 13102 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13103 | OneTimeCachingHostResolver host_resolver(HostPortPair("www.gmail.com", 443)); |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 13104 | HttpNetworkSession::Params params = |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13105 | SpdySessionDependencies::CreateSessionParams(&session_deps_); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13106 | params.host_resolver = &host_resolver; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13107 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 13108 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 13109 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13110 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13111 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13112 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13113 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13114 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13115 | scoped_ptr<SpdyFrame> host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13116 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13117 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13118 | scoped_ptr<SpdyFrame> host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13119 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13120 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13121 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13122 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13123 | scoped_ptr<SpdyFrame> host1_resp( |
| 13124 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13125 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 13126 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 13127 | scoped_ptr<SpdyFrame> host2_resp( |
| 13128 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 13129 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 13130 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13131 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13132 | CreateMockRead(*host1_resp, 1), |
| 13133 | CreateMockRead(*host1_resp_body, 2), |
| 13134 | CreateMockRead(*host2_resp, 4), |
| 13135 | CreateMockRead(*host2_resp_body, 5), |
| 13136 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13137 | }; |
| 13138 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13139 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13140 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13141 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13142 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13143 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13144 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 13145 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13146 | HttpRequestInfo request1; |
| 13147 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13148 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13149 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13150 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13151 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13152 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13153 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13154 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13155 | |
| 13156 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 13157 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13158 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13159 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13160 | |
| 13161 | std::string response_data; |
| 13162 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 13163 | EXPECT_EQ("hello!", response_data); |
| 13164 | |
| 13165 | // Preload cache entries into HostCache. |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 13166 | HostResolver::RequestInfo resolve_info(HostPortPair("www.gmail.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13167 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 13168 | rv = host_resolver.Resolve(resolve_info, |
| 13169 | DEFAULT_PRIORITY, |
| 13170 | &ignored, |
| 13171 | callback.callback(), |
| 13172 | NULL, |
| 13173 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 13174 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13175 | rv = callback.WaitForResult(); |
| 13176 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13177 | |
| 13178 | HttpRequestInfo request2; |
| 13179 | request2.method = "GET"; |
| 13180 | request2.url = GURL("https://www.gmail.com/"); |
| 13181 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13182 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13183 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13184 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13185 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13186 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13187 | |
| 13188 | response = trans2.GetResponseInfo(); |
| 13189 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13190 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13191 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13192 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13193 | EXPECT_TRUE(response->was_npn_negotiated); |
| 13194 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 13195 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13196 | } |
| 13197 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13198 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13199 | const std::string https_url = "https://www.example.org:8080/"; |
| 13200 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13201 | |
| 13202 | // SPDY GET for HTTPS URL |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13203 | scoped_ptr<SpdyFrame> req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13204 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13205 | |
| 13206 | MockWrite writes1[] = { |
| 13207 | CreateMockWrite(*req1, 0), |
| 13208 | }; |
| 13209 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13210 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13211 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 13212 | MockRead reads1[] = {CreateMockRead(*resp1, 1), CreateMockRead(*body1, 2), |
| 13213 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13214 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13215 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 13216 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13217 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13218 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13219 | |
| 13220 | // HTTP GET for the HTTP URL |
| 13221 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13222 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13223 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13224 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13225 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13226 | }; |
| 13227 | |
| 13228 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13229 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 13230 | MockRead(ASYNC, 2, "hello"), |
| 13231 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13232 | }; |
| 13233 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13234 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 13235 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13236 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13237 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13238 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13239 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13240 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13241 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13242 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13243 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13244 | |
| 13245 | // Start the first transaction to set up the SpdySession |
| 13246 | HttpRequestInfo request1; |
| 13247 | request1.method = "GET"; |
| 13248 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13249 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13250 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13251 | TestCompletionCallback callback1; |
| 13252 | EXPECT_EQ(ERR_IO_PENDING, |
| 13253 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 13254 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13255 | |
| 13256 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 13257 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 13258 | |
| 13259 | // Now, start the HTTP request |
| 13260 | HttpRequestInfo request2; |
| 13261 | request2.method = "GET"; |
| 13262 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13263 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13264 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13265 | TestCompletionCallback callback2; |
| 13266 | EXPECT_EQ(ERR_IO_PENDING, |
| 13267 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 13268 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13269 | |
| 13270 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 13271 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 13272 | } |
| 13273 | |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13274 | class AltSvcCertificateVerificationTest : public HttpNetworkTransactionTest { |
| 13275 | public: |
| 13276 | void Run(bool pooling, bool valid) { |
| 13277 | HostPortPair origin(valid ? "mail.example.org" : "invalid.example.org", |
| 13278 | 443); |
| 13279 | HostPortPair alternative("www.example.org", 443); |
| 13280 | |
| 13281 | base::FilePath certs_dir = GetTestCertsDirectory(); |
| 13282 | scoped_refptr<X509Certificate> cert( |
| 13283 | ImportCertFromFile(certs_dir, "spdy_pooling.pem")); |
| 13284 | ASSERT_TRUE(cert.get()); |
| 13285 | bool common_name_fallback_used; |
| 13286 | EXPECT_EQ(valid, |
| 13287 | cert->VerifyNameMatch(origin.host(), &common_name_fallback_used)); |
| 13288 | EXPECT_TRUE( |
| 13289 | cert->VerifyNameMatch(alternative.host(), &common_name_fallback_used)); |
| 13290 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13291 | ssl.SetNextProto(GetProtocol()); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13292 | ssl.cert = cert; |
| 13293 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13294 | |
| 13295 | // If pooling, then start a request to alternative first to create a |
| 13296 | // SpdySession. |
| 13297 | std::string url0 = "https://www.example.org:443"; |
| 13298 | // Second request to origin, which has an alternative service, and could |
| 13299 | // open a connection to the alternative host or pool to the existing one. |
| 13300 | std::string url1("https://"); |
| 13301 | url1.append(origin.host()); |
| 13302 | url1.append(":443"); |
| 13303 | |
| 13304 | scoped_ptr<SpdyFrame> req0; |
| 13305 | scoped_ptr<SpdyFrame> req1; |
| 13306 | scoped_ptr<SpdyFrame> resp0; |
| 13307 | scoped_ptr<SpdyFrame> body0; |
| 13308 | scoped_ptr<SpdyFrame> resp1; |
| 13309 | scoped_ptr<SpdyFrame> body1; |
| 13310 | std::vector<MockWrite> writes; |
| 13311 | std::vector<MockRead> reads; |
| 13312 | |
| 13313 | if (pooling) { |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13314 | req0.reset(spdy_util_.ConstructSpdyGet(url0.c_str(), 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13315 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13316 | req1.reset(spdy_util_.ConstructSpdyGet(url1.c_str(), 3, LOWEST)); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13317 | |
| 13318 | writes.push_back(CreateMockWrite(*req0, 0)); |
| 13319 | writes.push_back(CreateMockWrite(*req1, 3)); |
| 13320 | |
| 13321 | resp0.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13322 | body0.reset(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 13323 | resp1.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 13324 | body1.reset(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
| 13325 | |
| 13326 | reads.push_back(CreateMockRead(*resp0, 1)); |
| 13327 | reads.push_back(CreateMockRead(*body0, 2)); |
| 13328 | reads.push_back(MockRead(ASYNC, ERR_IO_PENDING, 4)); |
| 13329 | reads.push_back(CreateMockRead(*resp1, 5)); |
| 13330 | reads.push_back(CreateMockRead(*body1, 6)); |
| 13331 | reads.push_back(MockRead(ASYNC, OK, 7)); |
| 13332 | } else { |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13333 | req1.reset(spdy_util_.ConstructSpdyGet(url1.c_str(), 1, LOWEST)); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13334 | |
| 13335 | writes.push_back(CreateMockWrite(*req1, 0)); |
| 13336 | |
| 13337 | resp1.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13338 | body1.reset(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 13339 | |
| 13340 | reads.push_back(CreateMockRead(*resp1, 1)); |
| 13341 | reads.push_back(CreateMockRead(*body1, 2)); |
| 13342 | reads.push_back(MockRead(ASYNC, OK, 3)); |
| 13343 | } |
| 13344 | |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 13345 | SequencedSocketData data(reads.data(), reads.size(), writes.data(), |
| 13346 | writes.size()); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13347 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13348 | |
| 13349 | // Connection to the origin fails. |
| 13350 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 13351 | StaticSocketDataProvider data_refused; |
| 13352 | data_refused.set_connect_data(mock_connect); |
| 13353 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13354 | |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 13355 | session_deps_.parse_alternative_services = true; |
| 13356 | session_deps_.enable_alternative_service_with_different_host = true; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13357 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13358 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 13359 | session->http_server_properties(); |
| 13360 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13361 | AlternateProtocolFromNextProto(GetProtocol()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13362 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13363 | http_server_properties->SetAlternativeService(origin, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 13364 | expiration); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13365 | |
| 13366 | // First request to alternative. |
| 13367 | if (pooling) { |
| 13368 | scoped_ptr<HttpTransaction> trans0( |
| 13369 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13370 | HttpRequestInfo request0; |
| 13371 | request0.method = "GET"; |
| 13372 | request0.url = GURL(url0); |
| 13373 | request0.load_flags = 0; |
| 13374 | TestCompletionCallback callback0; |
| 13375 | |
| 13376 | int rv = trans0->Start(&request0, callback0.callback(), BoundNetLog()); |
| 13377 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13378 | rv = callback0.WaitForResult(); |
| 13379 | EXPECT_EQ(OK, rv); |
| 13380 | } |
| 13381 | |
| 13382 | // Second request to origin. |
| 13383 | scoped_ptr<HttpTransaction> trans1( |
| 13384 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13385 | HttpRequestInfo request1; |
| 13386 | request1.method = "GET"; |
| 13387 | request1.url = GURL(url1); |
| 13388 | request1.load_flags = 0; |
| 13389 | TestCompletionCallback callback1; |
| 13390 | |
| 13391 | int rv = trans1->Start(&request1, callback1.callback(), BoundNetLog()); |
| 13392 | EXPECT_EQ(ERR_IO_PENDING, rv); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 13393 | base::MessageLoop::current()->RunUntilIdle(); |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 13394 | if (data.IsPaused()) |
| 13395 | data.Resume(); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13396 | rv = callback1.WaitForResult(); |
| 13397 | if (valid) { |
| 13398 | EXPECT_EQ(OK, rv); |
| 13399 | } else { |
| 13400 | if (pooling) { |
| 13401 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 13402 | } else { |
| 13403 | EXPECT_EQ(ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN, rv); |
| 13404 | } |
| 13405 | } |
| 13406 | } |
| 13407 | }; |
| 13408 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13409 | INSTANTIATE_TEST_CASE_P(ProtoPlusDepend, |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13410 | AltSvcCertificateVerificationTest, |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13411 | testing::Values(kTestCaseSPDY31, |
| 13412 | kTestCaseHTTP2NoPriorityDependencies, |
| 13413 | kTestCaseHTTP2PriorityDependencies)); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13414 | |
| 13415 | // The alternative service host must exhibit a certificate that is valid for the |
| 13416 | // origin host. Test that this is enforced when pooling to an existing |
| 13417 | // connection. |
| 13418 | TEST_P(AltSvcCertificateVerificationTest, PoolingValid) { |
| 13419 | Run(true, true); |
| 13420 | } |
| 13421 | |
| 13422 | TEST_P(AltSvcCertificateVerificationTest, PoolingInvalid) { |
| 13423 | Run(true, false); |
| 13424 | } |
| 13425 | |
| 13426 | // The alternative service host must exhibit a certificate that is valid for the |
| 13427 | // origin host. Test that this is enforced when opening a new connection. |
| 13428 | TEST_P(AltSvcCertificateVerificationTest, NewConnectionValid) { |
| 13429 | Run(false, true); |
| 13430 | } |
| 13431 | |
| 13432 | TEST_P(AltSvcCertificateVerificationTest, NewConnectionInvalid) { |
| 13433 | Run(false, false); |
| 13434 | } |
| 13435 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13436 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 13437 | // with the alternative server. That connection should not be used. |
| 13438 | TEST_P(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
| 13439 | HostPortPair origin("origin.example.org", 443); |
| 13440 | HostPortPair alternative("alternative.example.org", 443); |
| 13441 | |
| 13442 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 13443 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13444 | ssl.SetNextProto(kProtoHTTP11); |
| 13445 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13446 | |
| 13447 | // No data should be read from the alternative, because HTTP/1.1 is |
| 13448 | // negotiated. |
| 13449 | StaticSocketDataProvider data; |
| 13450 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13451 | |
| 13452 | // This test documents that an alternate Job should not be used if HTTP/1.1 is |
| 13453 | // negotiated. In order to test this, a failed connection to the origin is |
| 13454 | // mocked. This way the request relies on the alternate Job. |
| 13455 | StaticSocketDataProvider data_refused; |
| 13456 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 13457 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13458 | |
| 13459 | // Set up alternative service for origin. |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 13460 | session_deps_.parse_alternative_services = true; |
| 13461 | session_deps_.enable_alternative_service_with_different_host = true; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13462 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13463 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 13464 | session->http_server_properties(); |
| 13465 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13466 | AlternateProtocolFromNextProto(GetProtocol()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13467 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13468 | http_server_properties->SetAlternativeService(origin, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 13469 | expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13470 | |
| 13471 | scoped_ptr<HttpTransaction> trans( |
| 13472 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13473 | HttpRequestInfo request; |
| 13474 | request.method = "GET"; |
| 13475 | request.url = GURL("https://origin.example.org:443"); |
| 13476 | request.load_flags = 0; |
| 13477 | TestCompletionCallback callback; |
| 13478 | |
| 13479 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
| 13480 | // negotiated, the alternate Job should fail with ERR_NPN_NEGOTIATION_FAILED. |
| 13481 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13482 | EXPECT_EQ(ERR_NPN_NEGOTIATION_FAILED, callback.GetResult(rv)); |
| 13483 | } |
| 13484 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13485 | // A request to a server with an alternative service fires two Jobs: one to the |
| 13486 | // origin, and an alternate one to the alternative server. If the former |
| 13487 | // succeeds, the request should succeed, even if the latter fails because |
| 13488 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
| 13489 | TEST_P(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
| 13490 | HostPortPair origin("origin.example.org", 443); |
| 13491 | HostPortPair alternative("alternative.example.org", 443); |
| 13492 | |
| 13493 | // Negotiate HTTP/1.1 with alternative. |
| 13494 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
| 13495 | alternative_ssl.SetNextProto(kProtoHTTP11); |
| 13496 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 13497 | |
| 13498 | // No data should be read from the alternative, because HTTP/1.1 is |
| 13499 | // negotiated. |
| 13500 | StaticSocketDataProvider data; |
| 13501 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13502 | |
| 13503 | // Negotiate HTTP/1.1 with origin. |
| 13504 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
| 13505 | origin_ssl.SetNextProto(kProtoHTTP11); |
| 13506 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 13507 | |
| 13508 | MockWrite http_writes[] = { |
| 13509 | MockWrite( |
| 13510 | "GET / HTTP/1.1\r\n" |
| 13511 | "Host: origin.example.org\r\n" |
| 13512 | "Connection: keep-alive\r\n\r\n"), |
| 13513 | MockWrite( |
| 13514 | "GET /second HTTP/1.1\r\n" |
| 13515 | "Host: origin.example.org\r\n" |
| 13516 | "Connection: keep-alive\r\n\r\n"), |
| 13517 | }; |
| 13518 | |
| 13519 | MockRead http_reads[] = { |
| 13520 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13521 | MockRead("Content-Type: text/html\r\n"), |
| 13522 | MockRead("Content-Length: 6\r\n\r\n"), |
| 13523 | MockRead("foobar"), |
| 13524 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13525 | MockRead("Content-Type: text/html\r\n"), |
| 13526 | MockRead("Content-Length: 7\r\n\r\n"), |
| 13527 | MockRead("another"), |
| 13528 | }; |
| 13529 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13530 | http_writes, arraysize(http_writes)); |
| 13531 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13532 | |
| 13533 | // Set up alternative service for origin. |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 13534 | session_deps_.parse_alternative_services = true; |
| 13535 | session_deps_.enable_alternative_service_with_different_host = true; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13536 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13537 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 13538 | session->http_server_properties(); |
| 13539 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13540 | AlternateProtocolFromNextProto(GetProtocol()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13541 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13542 | http_server_properties->SetAlternativeService(origin, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 13543 | expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13544 | |
| 13545 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 13546 | HttpRequestInfo request1; |
| 13547 | request1.method = "GET"; |
| 13548 | request1.url = GURL("https://origin.example.org:443"); |
| 13549 | request1.load_flags = 0; |
| 13550 | TestCompletionCallback callback1; |
| 13551 | |
| 13552 | int rv = trans1.Start(&request1, callback1.callback(), BoundNetLog()); |
| 13553 | rv = callback1.GetResult(rv); |
| 13554 | EXPECT_EQ(OK, rv); |
| 13555 | |
| 13556 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
| 13557 | ASSERT_TRUE(response1 != nullptr); |
| 13558 | ASSERT_TRUE(response1->headers.get() != nullptr); |
| 13559 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 13560 | |
| 13561 | std::string response_data1; |
| 13562 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data1)); |
| 13563 | EXPECT_EQ("foobar", response_data1); |
| 13564 | |
| 13565 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 13566 | // for alternative service. |
| 13567 | EXPECT_TRUE( |
| 13568 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 13569 | |
| 13570 | // Since |alternative_service| is broken, a second transaction to origin |
| 13571 | // should not start an alternate Job. It should pool to existing connection |
| 13572 | // to origin. |
| 13573 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 13574 | HttpRequestInfo request2; |
| 13575 | request2.method = "GET"; |
| 13576 | request2.url = GURL("https://origin.example.org:443/second"); |
| 13577 | request2.load_flags = 0; |
| 13578 | TestCompletionCallback callback2; |
| 13579 | |
| 13580 | rv = trans2.Start(&request2, callback2.callback(), BoundNetLog()); |
| 13581 | rv = callback2.GetResult(rv); |
| 13582 | EXPECT_EQ(OK, rv); |
| 13583 | |
| 13584 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
| 13585 | ASSERT_TRUE(response2 != nullptr); |
| 13586 | ASSERT_TRUE(response2->headers.get() != nullptr); |
| 13587 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 13588 | |
| 13589 | std::string response_data2; |
| 13590 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data2)); |
| 13591 | EXPECT_EQ("another", response_data2); |
| 13592 | } |
| 13593 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13594 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 13595 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 13596 | // used. |
| 13597 | TEST_P(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
| 13598 | HostPortPair origin("origin.example.org", 443); |
| 13599 | HostPortPair alternative("alternative.example.org", 443); |
| 13600 | std::string origin_url = "https://origin.example.org:443"; |
| 13601 | std::string alternative_url = "https://alternative.example.org:443"; |
| 13602 | |
| 13603 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 13604 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13605 | ssl.SetNextProto(kProtoHTTP11); |
| 13606 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13607 | |
| 13608 | // HTTP/1.1 data for |request1| and |request2|. |
| 13609 | MockWrite http_writes[] = { |
| 13610 | MockWrite( |
| 13611 | "GET / HTTP/1.1\r\n" |
| 13612 | "Host: alternative.example.org\r\n" |
| 13613 | "Connection: keep-alive\r\n\r\n"), |
| 13614 | MockWrite( |
| 13615 | "GET / HTTP/1.1\r\n" |
| 13616 | "Host: alternative.example.org\r\n" |
| 13617 | "Connection: keep-alive\r\n\r\n"), |
| 13618 | }; |
| 13619 | |
| 13620 | MockRead http_reads[] = { |
| 13621 | MockRead( |
| 13622 | "HTTP/1.1 200 OK\r\n" |
| 13623 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13624 | "Content-Length: 40\r\n\r\n" |
| 13625 | "first HTTP/1.1 response from alternative"), |
| 13626 | MockRead( |
| 13627 | "HTTP/1.1 200 OK\r\n" |
| 13628 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13629 | "Content-Length: 41\r\n\r\n" |
| 13630 | "second HTTP/1.1 response from alternative"), |
| 13631 | }; |
| 13632 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13633 | http_writes, arraysize(http_writes)); |
| 13634 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13635 | |
| 13636 | // This test documents that an alternate Job should not pool to an already |
| 13637 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
| 13638 | // to the origin is mocked. This way |request2| relies on the alternate Job. |
| 13639 | StaticSocketDataProvider data_refused; |
| 13640 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 13641 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13642 | |
| 13643 | // Set up alternative service for origin. |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 13644 | session_deps_.parse_alternative_services = true; |
| 13645 | session_deps_.enable_alternative_service_with_different_host = false; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13646 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13647 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 13648 | session->http_server_properties(); |
| 13649 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13650 | AlternateProtocolFromNextProto(GetProtocol()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13651 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13652 | http_server_properties->SetAlternativeService(origin, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 13653 | expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13654 | |
| 13655 | // First transaction to alternative to open an HTTP/1.1 socket. |
| 13656 | scoped_ptr<HttpTransaction> trans1( |
| 13657 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13658 | HttpRequestInfo request1; |
| 13659 | request1.method = "GET"; |
| 13660 | request1.url = GURL(alternative_url); |
| 13661 | request1.load_flags = 0; |
| 13662 | TestCompletionCallback callback1; |
| 13663 | |
| 13664 | int rv = trans1->Start(&request1, callback1.callback(), BoundNetLog()); |
| 13665 | EXPECT_EQ(OK, callback1.GetResult(rv)); |
| 13666 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 13667 | ASSERT_TRUE(response1); |
| 13668 | ASSERT_TRUE(response1->headers.get()); |
| 13669 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 13670 | EXPECT_TRUE(response1->was_npn_negotiated); |
| 13671 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 13672 | std::string response_data1; |
| 13673 | ASSERT_EQ(OK, ReadTransaction(trans1.get(), &response_data1)); |
| 13674 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 13675 | |
| 13676 | // Request for origin.example.org, which has an alternative service. This |
| 13677 | // will start two Jobs: the alternative looks for connections to pool to, |
| 13678 | // finds one which is HTTP/1.1, and should ignore it, and should not try to |
| 13679 | // open other connections to alternative server. The Job to origin fails, so |
| 13680 | // this request fails. |
| 13681 | scoped_ptr<HttpTransaction> trans2( |
| 13682 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13683 | HttpRequestInfo request2; |
| 13684 | request2.method = "GET"; |
| 13685 | request2.url = GURL(origin_url); |
| 13686 | request2.load_flags = 0; |
| 13687 | TestCompletionCallback callback2; |
| 13688 | |
| 13689 | rv = trans2->Start(&request2, callback2.callback(), BoundNetLog()); |
| 13690 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback2.GetResult(rv)); |
| 13691 | |
| 13692 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 13693 | // socket is still open and in the pool. |
| 13694 | scoped_ptr<HttpTransaction> trans3( |
| 13695 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13696 | HttpRequestInfo request3; |
| 13697 | request3.method = "GET"; |
| 13698 | request3.url = GURL(alternative_url); |
| 13699 | request3.load_flags = 0; |
| 13700 | TestCompletionCallback callback3; |
| 13701 | |
| 13702 | rv = trans3->Start(&request3, callback3.callback(), BoundNetLog()); |
| 13703 | EXPECT_EQ(OK, callback3.GetResult(rv)); |
| 13704 | const HttpResponseInfo* response3 = trans3->GetResponseInfo(); |
| 13705 | ASSERT_TRUE(response3); |
| 13706 | ASSERT_TRUE(response3->headers.get()); |
| 13707 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
| 13708 | EXPECT_TRUE(response3->was_npn_negotiated); |
| 13709 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 13710 | std::string response_data3; |
| 13711 | ASSERT_EQ(OK, ReadTransaction(trans3.get(), &response_data3)); |
| 13712 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 13713 | } |
| 13714 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13715 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13716 | const std::string https_url = "https://www.example.org:8080/"; |
| 13717 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13718 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13719 | // Separate SPDY util instance for naked and wrapped requests. |
| 13720 | SpdyTestUtil spdy_util_wrapped(GetProtocol(), GetDependenciesFromPriority()); |
| 13721 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13722 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13723 | const HostPortPair host_port_pair("www.example.org", 8080); |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13724 | scoped_ptr<SpdyFrame> connect( |
| 13725 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13726 | scoped_ptr<SpdyFrame> req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13727 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13728 | scoped_ptr<SpdyFrame> wrapped_req1( |
| 13729 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 13730 | |
| 13731 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13732 | SpdyHeaderBlock req2_block; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 13733 | spdy_util_.MaybeAddVersionHeader(&req2_block); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13734 | req2_block[spdy_util_.GetMethodKey()] = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13735 | req2_block[spdy_util_.GetHostKey()] = "www.example.org:8080"; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13736 | req2_block[spdy_util_.GetSchemeKey()] = "http"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 13737 | req2_block[spdy_util_.GetPathKey()] = "/"; |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 13738 | scoped_ptr<SpdyFrame> req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13739 | spdy_util_.ConstructSpdySyn(3, req2_block, MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13740 | |
| 13741 | MockWrite writes1[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13742 | CreateMockWrite(*connect, 0), CreateMockWrite(*wrapped_req1, 2), |
| 13743 | CreateMockWrite(*req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13744 | }; |
| 13745 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13746 | scoped_ptr<SpdyFrame> conn_resp( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13747 | spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
| 13748 | scoped_ptr<SpdyFrame> resp1( |
| 13749 | spdy_util_wrapped.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
| 13750 | scoped_ptr<SpdyFrame> body1( |
| 13751 | spdy_util_wrapped.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13752 | scoped_ptr<SpdyFrame> wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13753 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13754 | scoped_ptr<SpdyFrame> wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13755 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13756 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 13757 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13758 | MockRead reads1[] = { |
| 13759 | CreateMockRead(*conn_resp, 1), |
| 13760 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 13761 | CreateMockRead(*wrapped_resp1, 4), |
| 13762 | CreateMockRead(*wrapped_body1, 5), |
| 13763 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
| 13764 | CreateMockRead(*resp2, 8), |
| 13765 | CreateMockRead(*body2, 9), |
| 13766 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 13767 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13768 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13769 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 13770 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13771 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13772 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13773 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13774 | session_deps_.proxy_service = |
| 13775 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13776 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13777 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13778 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13779 | ssl1.SetNextProto(GetProtocol()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13780 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13781 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13782 | ssl2.SetNextProto(GetProtocol()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13783 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13784 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13785 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13786 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13787 | |
| 13788 | // Start the first transaction to set up the SpdySession |
| 13789 | HttpRequestInfo request1; |
| 13790 | request1.method = "GET"; |
| 13791 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13792 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13793 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13794 | TestCompletionCallback callback1; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13795 | int rv = trans1.Start(&request1, callback1.callback(), BoundNetLog()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13796 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13797 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 13798 | data1.RunUntilPaused(); |
| 13799 | base::RunLoop().RunUntilIdle(); |
| 13800 | data1.Resume(); |
| 13801 | EXPECT_EQ(OK, callback1.GetResult(rv)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13802 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 13803 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 13804 | LoadTimingInfo load_timing_info1; |
| 13805 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 13806 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 13807 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 13808 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13809 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13810 | HttpRequestInfo request2; |
| 13811 | request2.method = "GET"; |
| 13812 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13813 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13814 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13815 | TestCompletionCallback callback2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13816 | rv = trans2.Start(&request2, callback2.callback(), BoundNetLog()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13817 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13818 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 13819 | data1.RunUntilPaused(); |
| 13820 | base::RunLoop().RunUntilIdle(); |
| 13821 | data1.Resume(); |
| 13822 | EXPECT_EQ(OK, callback2.GetResult(rv)); |
| 13823 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13824 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 13825 | |
| 13826 | LoadTimingInfo load_timing_info2; |
| 13827 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 13828 | // The established SPDY sessions is considered reused by the HTTP request. |
| 13829 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 13830 | // HTTP requests over a SPDY session should have a different connection |
| 13831 | // socket_log_id than requests over a tunnel. |
| 13832 | 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] | 13833 | } |
| 13834 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13835 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 13836 | // that we do not pool other origins that resolve to the same IP when |
| 13837 | // the certificate does not match the new origin. |
| 13838 | // http://crbug.com/134690 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13839 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13840 | const std::string url1 = "http://www.example.org/"; |
| 13841 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13842 | const std::string ip_addr = "1.2.3.4"; |
| 13843 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13844 | // Second SpdyTestUtil instance for the second socket. |
| 13845 | SpdyTestUtil spdy_util_secure(GetProtocol(), GetDependenciesFromPriority()); |
| 13846 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13847 | // SPDY GET for HTTP URL (through SPDY proxy) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13848 | scoped_ptr<SpdyHeaderBlock> headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13849 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13850 | scoped_ptr<SpdyFrame> req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13851 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13852 | |
| 13853 | MockWrite writes1[] = { |
| 13854 | CreateMockWrite(*req1, 0), |
| 13855 | }; |
| 13856 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13857 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13858 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13859 | MockRead reads1[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13860 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(*resp1, 2), |
| 13861 | CreateMockRead(*body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13862 | }; |
| 13863 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13864 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 13865 | arraysize(writes1)); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 13866 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 13867 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13868 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 13869 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13870 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13871 | |
| 13872 | // SPDY GET for HTTPS URL (direct) |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13873 | scoped_ptr<SpdyFrame> req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13874 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13875 | |
| 13876 | MockWrite writes2[] = { |
| 13877 | CreateMockWrite(*req2, 0), |
| 13878 | }; |
| 13879 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13880 | scoped_ptr<SpdyFrame> resp2( |
| 13881 | spdy_util_secure.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13882 | scoped_ptr<SpdyFrame> body2(spdy_util_secure.ConstructSpdyBodyFrame(1, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13883 | MockRead reads2[] = {CreateMockRead(*resp2, 1), CreateMockRead(*body2, 2), |
| 13884 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13885 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13886 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 13887 | arraysize(writes2)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13888 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13889 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13890 | |
| 13891 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 13892 | // all others direct. |
| 13893 | ProxyConfig proxy_config; |
| 13894 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13895 | session_deps_.proxy_service.reset(new ProxyService( |
csharrison | b7e3a08 | 2015-09-22 19:13:04 | [diff] [blame] | 13896 | make_scoped_ptr(new ProxyConfigServiceFixed(proxy_config)), nullptr, |
| 13897 | NULL)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13898 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13899 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13900 | ssl1.SetNextProto(GetProtocol()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13901 | // Load a valid cert. Note, that this does not need to |
| 13902 | // be valid for proxy because the MockSSLClientSocket does |
| 13903 | // not actually verify it. But SpdySession will use this |
| 13904 | // to see if it is valid for the new origin |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13905 | ssl1.cert = ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 13906 | ASSERT_TRUE(ssl1.cert.get()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13907 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 13908 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13909 | |
| 13910 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13911 | ssl2.SetNextProto(GetProtocol()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13912 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13913 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13914 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13915 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13916 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13917 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13918 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13919 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13920 | |
| 13921 | // Start the first transaction to set up the SpdySession |
| 13922 | HttpRequestInfo request1; |
| 13923 | request1.method = "GET"; |
| 13924 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13925 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13926 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13927 | TestCompletionCallback callback1; |
| 13928 | ASSERT_EQ(ERR_IO_PENDING, |
| 13929 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13930 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 13931 | data1.RunUntilPaused(); |
| 13932 | base::RunLoop().RunUntilIdle(); |
| 13933 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13934 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13935 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 13936 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 13937 | |
| 13938 | // Now, start the HTTP request |
| 13939 | HttpRequestInfo request2; |
| 13940 | request2.method = "GET"; |
| 13941 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13942 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13943 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13944 | TestCompletionCallback callback2; |
| 13945 | EXPECT_EQ(ERR_IO_PENDING, |
| 13946 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 13947 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13948 | |
| 13949 | ASSERT_TRUE(callback2.have_result()); |
| 13950 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 13951 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 13952 | } |
| 13953 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13954 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 13955 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 13956 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 13957 | // SpdySession) do work. http://crbug.com/224701 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13958 | TEST_P(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13959 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13960 | |
| 13961 | MockRead reads1[] = { |
| 13962 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 13963 | }; |
| 13964 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13965 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13966 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13967 | scoped_ptr<SpdyFrame> req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13968 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13969 | MockWrite writes2[] = { |
| 13970 | CreateMockWrite(*req2, 0), |
| 13971 | }; |
| 13972 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13973 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13974 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13975 | MockRead reads2[] = { |
| 13976 | CreateMockRead(*resp2, 1), |
| 13977 | CreateMockRead(*body2, 2), |
| 13978 | MockRead(ASYNC, OK, 3) // EOF |
| 13979 | }; |
| 13980 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13981 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 13982 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13983 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13984 | SSLSocketDataProvider ssl1(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13985 | ssl1.SetNextProto(GetProtocol()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13986 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 13987 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13988 | |
| 13989 | SSLSocketDataProvider ssl2(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13990 | ssl2.SetNextProto(GetProtocol()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13991 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13992 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13993 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13994 | scoped_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13995 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13996 | |
| 13997 | // Start the first transaction to set up the SpdySession and verify that |
| 13998 | // connection was closed. |
| 13999 | HttpRequestInfo request1; |
| 14000 | request1.method = "GET"; |
| 14001 | request1.url = GURL(https_url); |
| 14002 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14003 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14004 | TestCompletionCallback callback1; |
| 14005 | EXPECT_EQ(ERR_IO_PENDING, |
| 14006 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14007 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback1.WaitForResult()); |
| 14008 | |
| 14009 | // Now, start the second request and make sure it succeeds. |
| 14010 | HttpRequestInfo request2; |
| 14011 | request2.method = "GET"; |
| 14012 | request2.url = GURL(https_url); |
| 14013 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14014 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14015 | TestCompletionCallback callback2; |
| 14016 | EXPECT_EQ(ERR_IO_PENDING, |
| 14017 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14018 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14019 | ASSERT_EQ(OK, callback2.WaitForResult()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14020 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14021 | } |
| 14022 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 14023 | TEST_P(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14024 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 14025 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14026 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 14027 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14028 | |
| 14029 | // Use two different hosts with different IPs so they don't get pooled. |
| 14030 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 14031 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14032 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14033 | |
| 14034 | SSLSocketDataProvider ssl1(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14035 | ssl1.SetNextProto(GetProtocol()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14036 | SSLSocketDataProvider ssl2(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14037 | ssl2.SetNextProto(GetProtocol()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14038 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14039 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14040 | |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14041 | scoped_ptr<SpdyFrame> host1_req( |
| 14042 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14043 | MockWrite spdy1_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14044 | CreateMockWrite(*host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14045 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 14046 | scoped_ptr<SpdyFrame> host1_resp( |
| 14047 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 14048 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 14049 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14050 | MockRead spdy1_reads[] = { |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14051 | CreateMockRead(*host1_resp, 1), CreateMockRead(*host1_resp_body, 2), |
| 14052 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14053 | }; |
| 14054 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14055 | // Use a separate test instance for the separate SpdySession that will be |
| 14056 | // created. |
| 14057 | SpdyTestUtil spdy_util_2(GetProtocol(), GetDependenciesFromPriority()); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14058 | scoped_ptr<SequencedSocketData> spdy1_data( |
| 14059 | new SequencedSocketData(spdy1_reads, arraysize(spdy1_reads), spdy1_writes, |
| 14060 | arraysize(spdy1_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14061 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 14062 | |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14063 | scoped_ptr<SpdyFrame> host2_req( |
| 14064 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14065 | MockWrite spdy2_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14066 | CreateMockWrite(*host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14067 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 14068 | scoped_ptr<SpdyFrame> host2_resp( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14069 | spdy_util_2.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 14070 | scoped_ptr<SpdyFrame> host2_resp_body( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14071 | spdy_util_2.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14072 | MockRead spdy2_reads[] = { |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14073 | CreateMockRead(*host2_resp, 1), CreateMockRead(*host2_resp_body, 2), |
| 14074 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14075 | }; |
| 14076 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14077 | scoped_ptr<SequencedSocketData> spdy2_data( |
| 14078 | new SequencedSocketData(spdy2_reads, arraysize(spdy2_reads), spdy2_writes, |
| 14079 | arraysize(spdy2_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14080 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 14081 | |
| 14082 | MockWrite http_write[] = { |
| 14083 | MockWrite("GET / HTTP/1.1\r\n" |
| 14084 | "Host: www.a.com\r\n" |
| 14085 | "Connection: keep-alive\r\n\r\n"), |
| 14086 | }; |
| 14087 | |
| 14088 | MockRead http_read[] = { |
| 14089 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14090 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14091 | MockRead("Content-Length: 6\r\n\r\n"), |
| 14092 | MockRead("hello!"), |
| 14093 | }; |
| 14094 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 14095 | http_write, arraysize(http_write)); |
| 14096 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14097 | |
| 14098 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14099 | SpdySessionKey spdy_session_key_a( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14100 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14101 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14102 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14103 | |
| 14104 | TestCompletionCallback callback; |
| 14105 | HttpRequestInfo request1; |
| 14106 | request1.method = "GET"; |
| 14107 | request1.url = GURL("https://www.a.com/"); |
| 14108 | request1.load_flags = 0; |
| 14109 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14110 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14111 | |
| 14112 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 14113 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14114 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 14115 | |
| 14116 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14117 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14118 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14119 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14120 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14121 | EXPECT_TRUE(response->was_npn_negotiated); |
| 14122 | |
| 14123 | std::string response_data; |
| 14124 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 14125 | EXPECT_EQ("hello!", response_data); |
| 14126 | trans.reset(); |
| 14127 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14128 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14129 | |
| 14130 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14131 | SpdySessionKey spdy_session_key_b( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14132 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14133 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14134 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14135 | HttpRequestInfo request2; |
| 14136 | request2.method = "GET"; |
| 14137 | request2.url = GURL("https://www.b.com/"); |
| 14138 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14139 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14140 | |
| 14141 | rv = trans->Start(&request2, callback.callback(), BoundNetLog()); |
| 14142 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14143 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 14144 | |
| 14145 | response = trans->GetResponseInfo(); |
| 14146 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14147 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14148 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14149 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14150 | EXPECT_TRUE(response->was_npn_negotiated); |
| 14151 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 14152 | EXPECT_EQ("hello!", response_data); |
| 14153 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14154 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14155 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14156 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14157 | |
| 14158 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14159 | SpdySessionKey spdy_session_key_a1( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14160 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14161 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14162 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14163 | HttpRequestInfo request3; |
| 14164 | request3.method = "GET"; |
| 14165 | request3.url = GURL("http://www.a.com/"); |
| 14166 | request3.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14167 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14168 | |
| 14169 | rv = trans->Start(&request3, callback.callback(), BoundNetLog()); |
| 14170 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14171 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 14172 | |
| 14173 | response = trans->GetResponseInfo(); |
| 14174 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14175 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14176 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14177 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 14178 | EXPECT_FALSE(response->was_npn_negotiated); |
| 14179 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 14180 | EXPECT_EQ("hello!", response_data); |
| 14181 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14182 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14183 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14184 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14185 | } |
| 14186 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14187 | TEST_P(HttpNetworkTransactionTest, HttpSyncConnectError) { |
| 14188 | HttpRequestInfo request; |
| 14189 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14190 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14191 | request.load_flags = 0; |
| 14192 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14193 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14194 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14195 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14196 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14197 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14198 | StaticSocketDataProvider data; |
| 14199 | data.set_connect_data(mock_connect); |
| 14200 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14201 | |
| 14202 | TestCompletionCallback callback; |
| 14203 | |
| 14204 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14205 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14206 | |
| 14207 | rv = callback.WaitForResult(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14208 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14209 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14210 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 14211 | HttpRequestHeaders request_headers; |
| 14212 | trans->GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14213 | |
| 14214 | ConnectionAttempts attempts; |
| 14215 | trans->GetConnectionAttempts(&attempts); |
| 14216 | ASSERT_EQ(1u, attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14217 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, attempts[0].result); |
| 14218 | |
| 14219 | IPEndPoint endpoint; |
| 14220 | EXPECT_FALSE(trans->GetRemoteEndpoint(&endpoint)); |
| 14221 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14222 | } |
| 14223 | |
| 14224 | TEST_P(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
| 14225 | HttpRequestInfo request; |
| 14226 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14227 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14228 | request.load_flags = 0; |
| 14229 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14230 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14231 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14232 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14233 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14234 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14235 | StaticSocketDataProvider data; |
| 14236 | data.set_connect_data(mock_connect); |
| 14237 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14238 | |
| 14239 | TestCompletionCallback callback; |
| 14240 | |
| 14241 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14242 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14243 | |
| 14244 | rv = callback.WaitForResult(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14245 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14246 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14247 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 14248 | HttpRequestHeaders request_headers; |
| 14249 | trans->GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14250 | |
| 14251 | ConnectionAttempts attempts; |
| 14252 | trans->GetConnectionAttempts(&attempts); |
| 14253 | ASSERT_EQ(1u, attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14254 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, attempts[0].result); |
| 14255 | |
| 14256 | IPEndPoint endpoint; |
| 14257 | EXPECT_FALSE(trans->GetRemoteEndpoint(&endpoint)); |
| 14258 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14259 | } |
| 14260 | |
| 14261 | TEST_P(HttpNetworkTransactionTest, HttpSyncWriteError) { |
| 14262 | HttpRequestInfo request; |
| 14263 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14264 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14265 | request.load_flags = 0; |
| 14266 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14267 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14268 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14269 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14270 | |
| 14271 | MockWrite data_writes[] = { |
| 14272 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14273 | }; |
| 14274 | MockRead data_reads[] = { |
| 14275 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 14276 | }; |
| 14277 | |
| 14278 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14279 | data_writes, arraysize(data_writes)); |
| 14280 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14281 | |
| 14282 | TestCompletionCallback callback; |
| 14283 | |
| 14284 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14285 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14286 | |
| 14287 | rv = callback.WaitForResult(); |
| 14288 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 14289 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14290 | HttpRequestHeaders request_headers; |
| 14291 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 14292 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14293 | } |
| 14294 | |
| 14295 | TEST_P(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
| 14296 | HttpRequestInfo request; |
| 14297 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14298 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14299 | request.load_flags = 0; |
| 14300 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14301 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14302 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14303 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14304 | |
| 14305 | MockWrite data_writes[] = { |
| 14306 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 14307 | }; |
| 14308 | MockRead data_reads[] = { |
| 14309 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 14310 | }; |
| 14311 | |
| 14312 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14313 | data_writes, arraysize(data_writes)); |
| 14314 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14315 | |
| 14316 | TestCompletionCallback callback; |
| 14317 | |
| 14318 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14319 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14320 | |
| 14321 | rv = callback.WaitForResult(); |
| 14322 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 14323 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14324 | HttpRequestHeaders request_headers; |
| 14325 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 14326 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14327 | } |
| 14328 | |
| 14329 | TEST_P(HttpNetworkTransactionTest, HttpSyncReadError) { |
| 14330 | HttpRequestInfo request; |
| 14331 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14332 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14333 | request.load_flags = 0; |
| 14334 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14335 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14336 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14337 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14338 | |
| 14339 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14340 | MockWrite( |
| 14341 | "GET / HTTP/1.1\r\n" |
| 14342 | "Host: www.example.org\r\n" |
| 14343 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14344 | }; |
| 14345 | MockRead data_reads[] = { |
| 14346 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14347 | }; |
| 14348 | |
| 14349 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14350 | data_writes, arraysize(data_writes)); |
| 14351 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14352 | |
| 14353 | TestCompletionCallback callback; |
| 14354 | |
| 14355 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14356 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14357 | |
| 14358 | rv = callback.WaitForResult(); |
| 14359 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 14360 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14361 | HttpRequestHeaders request_headers; |
| 14362 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 14363 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14364 | } |
| 14365 | |
| 14366 | TEST_P(HttpNetworkTransactionTest, HttpAsyncReadError) { |
| 14367 | HttpRequestInfo request; |
| 14368 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14369 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14370 | request.load_flags = 0; |
| 14371 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14372 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14373 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14374 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14375 | |
| 14376 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14377 | MockWrite( |
| 14378 | "GET / HTTP/1.1\r\n" |
| 14379 | "Host: www.example.org\r\n" |
| 14380 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14381 | }; |
| 14382 | MockRead data_reads[] = { |
| 14383 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 14384 | }; |
| 14385 | |
| 14386 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14387 | data_writes, arraysize(data_writes)); |
| 14388 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14389 | |
| 14390 | TestCompletionCallback callback; |
| 14391 | |
| 14392 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14393 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14394 | |
| 14395 | rv = callback.WaitForResult(); |
| 14396 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 14397 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14398 | HttpRequestHeaders request_headers; |
| 14399 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 14400 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14401 | } |
| 14402 | |
| 14403 | TEST_P(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
| 14404 | HttpRequestInfo request; |
| 14405 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14406 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14407 | request.load_flags = 0; |
| 14408 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 14409 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14410 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14411 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14412 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14413 | |
| 14414 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14415 | MockWrite( |
| 14416 | "GET / HTTP/1.1\r\n" |
| 14417 | "Host: www.example.org\r\n" |
| 14418 | "Connection: keep-alive\r\n" |
| 14419 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14420 | }; |
| 14421 | MockRead data_reads[] = { |
| 14422 | MockRead("HTTP/1.1 200 OK\r\n" |
| 14423 | "Content-Length: 5\r\n\r\n" |
| 14424 | "hello"), |
| 14425 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 14426 | }; |
| 14427 | |
| 14428 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14429 | data_writes, arraysize(data_writes)); |
| 14430 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14431 | |
| 14432 | TestCompletionCallback callback; |
| 14433 | |
| 14434 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14435 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14436 | |
| 14437 | rv = callback.WaitForResult(); |
| 14438 | EXPECT_EQ(OK, rv); |
| 14439 | |
| 14440 | HttpRequestHeaders request_headers; |
| 14441 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 14442 | std::string foo; |
| 14443 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 14444 | EXPECT_EQ("bar", foo); |
| 14445 | } |
| 14446 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14447 | namespace { |
| 14448 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 14449 | // Fake HttpStream that simply records calls to SetPriority(). |
| 14450 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14451 | public base::SupportsWeakPtr<FakeStream> { |
| 14452 | public: |
| 14453 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14454 | ~FakeStream() override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14455 | |
| 14456 | RequestPriority priority() const { return priority_; } |
| 14457 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14458 | int InitializeStream(const HttpRequestInfo* request_info, |
| 14459 | RequestPriority priority, |
| 14460 | const BoundNetLog& net_log, |
| 14461 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14462 | return ERR_IO_PENDING; |
| 14463 | } |
| 14464 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14465 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 14466 | HttpResponseInfo* response, |
| 14467 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14468 | ADD_FAILURE(); |
| 14469 | return ERR_UNEXPECTED; |
| 14470 | } |
| 14471 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14472 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14473 | ADD_FAILURE(); |
| 14474 | return ERR_UNEXPECTED; |
| 14475 | } |
| 14476 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14477 | int ReadResponseBody(IOBuffer* buf, |
| 14478 | int buf_len, |
| 14479 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14480 | ADD_FAILURE(); |
| 14481 | return ERR_UNEXPECTED; |
| 14482 | } |
| 14483 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14484 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14485 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14486 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14487 | ADD_FAILURE(); |
| 14488 | return false; |
| 14489 | } |
| 14490 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14491 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14492 | ADD_FAILURE(); |
| 14493 | return false; |
| 14494 | } |
| 14495 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14496 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14497 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 14498 | bool CanReuseConnection() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14499 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 14500 | int64_t GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 14501 | ADD_FAILURE(); |
| 14502 | return 0; |
| 14503 | } |
| 14504 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 14505 | int64_t GetTotalSentBytes() const override { |
| 14506 | ADD_FAILURE(); |
| 14507 | return 0; |
| 14508 | } |
| 14509 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14510 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14511 | ADD_FAILURE(); |
| 14512 | return false; |
| 14513 | } |
| 14514 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14515 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 14516 | |
| 14517 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14518 | ADD_FAILURE(); |
| 14519 | } |
| 14520 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14521 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 14522 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 14523 | Error GetSignedEKMForTokenBinding(crypto::ECPrivateKey* key, |
| 14524 | std::vector<uint8_t>* out) override { |
| 14525 | ADD_FAILURE(); |
| 14526 | return ERR_NOT_IMPLEMENTED; |
| 14527 | } |
| 14528 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14529 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14530 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 14531 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 14532 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14533 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14534 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 14535 | UploadProgress GetUploadProgress() const override { return UploadProgress(); } |
| 14536 | |
| 14537 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 14538 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14539 | private: |
| 14540 | RequestPriority priority_; |
| 14541 | |
| 14542 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 14543 | }; |
| 14544 | |
| 14545 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 14546 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14547 | class FakeStreamRequest : public HttpStreamRequest, |
| 14548 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 14549 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14550 | FakeStreamRequest(RequestPriority priority, |
| 14551 | HttpStreamRequest::Delegate* delegate) |
| 14552 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14553 | delegate_(delegate), |
| 14554 | websocket_stream_create_helper_(NULL) {} |
| 14555 | |
| 14556 | FakeStreamRequest(RequestPriority priority, |
| 14557 | HttpStreamRequest::Delegate* delegate, |
| 14558 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 14559 | : priority_(priority), |
| 14560 | delegate_(delegate), |
| 14561 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14562 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14563 | ~FakeStreamRequest() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14564 | |
| 14565 | RequestPriority priority() const { return priority_; } |
| 14566 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14567 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 14568 | websocket_stream_create_helper() const { |
| 14569 | return websocket_stream_create_helper_; |
| 14570 | } |
| 14571 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14572 | // Create a new FakeStream and pass it to the request's |
| 14573 | // delegate. Returns a weak pointer to the FakeStream. |
| 14574 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
| 14575 | FakeStream* fake_stream = new FakeStream(priority_); |
| 14576 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 14577 | // immediately delete |fake_stream|. |
| 14578 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
| 14579 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), fake_stream); |
| 14580 | return weak_stream; |
| 14581 | } |
| 14582 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14583 | int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14584 | ADD_FAILURE(); |
| 14585 | return ERR_UNEXPECTED; |
| 14586 | } |
| 14587 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14588 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14589 | ADD_FAILURE(); |
| 14590 | return LoadState(); |
| 14591 | } |
| 14592 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14593 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14594 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14595 | bool was_npn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14596 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14597 | NextProto protocol_negotiated() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14598 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14599 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14600 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14601 | const ConnectionAttempts& connection_attempts() const override { |
| 14602 | static ConnectionAttempts no_attempts; |
| 14603 | return no_attempts; |
| 14604 | } |
| 14605 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14606 | private: |
| 14607 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14608 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14609 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14610 | |
| 14611 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 14612 | }; |
| 14613 | |
| 14614 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 14615 | class FakeStreamFactory : public HttpStreamFactory { |
| 14616 | public: |
| 14617 | FakeStreamFactory() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14618 | ~FakeStreamFactory() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14619 | |
| 14620 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 14621 | // RequestStream() (which may be NULL if it was destroyed already). |
| 14622 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 14623 | return last_stream_request_; |
| 14624 | } |
| 14625 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14626 | HttpStreamRequest* RequestStream(const HttpRequestInfo& info, |
| 14627 | RequestPriority priority, |
| 14628 | const SSLConfig& server_ssl_config, |
| 14629 | const SSLConfig& proxy_ssl_config, |
| 14630 | HttpStreamRequest::Delegate* delegate, |
| 14631 | const BoundNetLog& net_log) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14632 | FakeStreamRequest* fake_request = new FakeStreamRequest(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14633 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 14634 | return fake_request; |
| 14635 | } |
| 14636 | |
xunjieli | 5749218c | 2016-03-22 16:43:06 | [diff] [blame^] | 14637 | HttpStreamRequest* RequestBidirectionalStreamImpl( |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 14638 | const HttpRequestInfo& info, |
| 14639 | RequestPriority priority, |
| 14640 | const SSLConfig& server_ssl_config, |
| 14641 | const SSLConfig& proxy_ssl_config, |
| 14642 | HttpStreamRequest::Delegate* delegate, |
| 14643 | const BoundNetLog& net_log) override { |
| 14644 | NOTREACHED(); |
| 14645 | return nullptr; |
| 14646 | } |
| 14647 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14648 | HttpStreamRequest* RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14649 | const HttpRequestInfo& info, |
| 14650 | RequestPriority priority, |
| 14651 | const SSLConfig& server_ssl_config, |
| 14652 | const SSLConfig& proxy_ssl_config, |
| 14653 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 14654 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 14655 | const BoundNetLog& net_log) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14656 | FakeStreamRequest* fake_request = |
| 14657 | new FakeStreamRequest(priority, delegate, create_helper); |
| 14658 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 14659 | return fake_request; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14660 | } |
| 14661 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14662 | void PreconnectStreams(int num_streams, |
| 14663 | const HttpRequestInfo& info, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14664 | const SSLConfig& server_ssl_config, |
| 14665 | const SSLConfig& proxy_ssl_config) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14666 | ADD_FAILURE(); |
| 14667 | } |
| 14668 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14669 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14670 | ADD_FAILURE(); |
| 14671 | return NULL; |
| 14672 | } |
| 14673 | |
| 14674 | private: |
| 14675 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 14676 | |
| 14677 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 14678 | }; |
| 14679 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14680 | // TODO(ricea): Maybe unify this with the one in |
| 14681 | // url_request_http_job_unittest.cc ? |
| 14682 | class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { |
| 14683 | public: |
| 14684 | FakeWebSocketBasicHandshakeStream(scoped_ptr<ClientSocketHandle> connection, |
| 14685 | bool using_proxy) |
| 14686 | : state_(connection.release(), using_proxy) {} |
| 14687 | |
| 14688 | // Fake implementation of HttpStreamBase methods. |
| 14689 | // This ends up being quite "real" because this object has to really send data |
| 14690 | // on the mock socket. It might be easier to use the real implementation, but |
| 14691 | // the fact that the WebSocket code is not compiled on iOS makes that |
| 14692 | // difficult. |
| 14693 | int InitializeStream(const HttpRequestInfo* request_info, |
| 14694 | RequestPriority priority, |
| 14695 | const BoundNetLog& net_log, |
| 14696 | const CompletionCallback& callback) override { |
| 14697 | state_.Initialize(request_info, priority, net_log, callback); |
| 14698 | return OK; |
| 14699 | } |
| 14700 | |
| 14701 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 14702 | HttpResponseInfo* response, |
| 14703 | const CompletionCallback& callback) override { |
| 14704 | return parser()->SendRequest(state_.GenerateRequestLine(), request_headers, |
| 14705 | response, callback); |
| 14706 | } |
| 14707 | |
| 14708 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
| 14709 | return parser()->ReadResponseHeaders(callback); |
| 14710 | } |
| 14711 | |
| 14712 | int ReadResponseBody(IOBuffer* buf, |
| 14713 | int buf_len, |
| 14714 | const CompletionCallback& callback) override { |
| 14715 | NOTREACHED(); |
| 14716 | return ERR_IO_PENDING; |
| 14717 | } |
| 14718 | |
| 14719 | void Close(bool not_reusable) override { |
| 14720 | if (parser()) |
| 14721 | parser()->Close(true); |
| 14722 | } |
| 14723 | |
| 14724 | bool IsResponseBodyComplete() const override { |
| 14725 | NOTREACHED(); |
| 14726 | return false; |
| 14727 | } |
| 14728 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14729 | bool IsConnectionReused() const override { |
| 14730 | NOTREACHED(); |
| 14731 | return false; |
| 14732 | } |
| 14733 | void SetConnectionReused() override { NOTREACHED(); } |
| 14734 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 14735 | bool CanReuseConnection() const override { return false; } |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14736 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 14737 | int64_t GetTotalReceivedBytes() const override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14738 | NOTREACHED(); |
| 14739 | return 0; |
| 14740 | } |
| 14741 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 14742 | int64_t GetTotalSentBytes() const override { |
| 14743 | NOTREACHED(); |
| 14744 | return 0; |
| 14745 | } |
| 14746 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14747 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
| 14748 | NOTREACHED(); |
| 14749 | return false; |
| 14750 | } |
| 14751 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 14752 | void GetSSLInfo(SSLInfo* ssl_info) override {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14753 | |
| 14754 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
| 14755 | NOTREACHED(); |
| 14756 | } |
| 14757 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14758 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 14759 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 14760 | Error GetSignedEKMForTokenBinding(crypto::ECPrivateKey* key, |
| 14761 | std::vector<uint8_t>* out) override { |
| 14762 | ADD_FAILURE(); |
| 14763 | return ERR_NOT_IMPLEMENTED; |
| 14764 | } |
| 14765 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14766 | void Drain(HttpNetworkSession* session) override { NOTREACHED(); } |
| 14767 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 14768 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 14769 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14770 | void SetPriority(RequestPriority priority) override { NOTREACHED(); } |
| 14771 | |
| 14772 | UploadProgress GetUploadProgress() const override { |
| 14773 | NOTREACHED(); |
| 14774 | return UploadProgress(); |
| 14775 | } |
| 14776 | |
| 14777 | HttpStream* RenewStreamForAuth() override { |
| 14778 | NOTREACHED(); |
| 14779 | return nullptr; |
| 14780 | } |
| 14781 | |
| 14782 | // Fake implementation of WebSocketHandshakeStreamBase method(s) |
| 14783 | scoped_ptr<WebSocketStream> Upgrade() override { |
| 14784 | NOTREACHED(); |
| 14785 | return scoped_ptr<WebSocketStream>(); |
| 14786 | } |
| 14787 | |
| 14788 | private: |
| 14789 | HttpStreamParser* parser() const { return state_.parser(); } |
| 14790 | HttpBasicState state_; |
| 14791 | |
| 14792 | DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream); |
| 14793 | }; |
| 14794 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14795 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 14796 | // worth doing. |
| 14797 | class FakeWebSocketStreamCreateHelper : |
| 14798 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 14799 | public: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14800 | WebSocketHandshakeStreamBase* CreateBasicStream( |
[email protected] | 7e841a5 | 2013-11-22 09:04:21 | [diff] [blame] | 14801 | scoped_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 14802 | bool using_proxy) override { |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 14803 | return new FakeWebSocketBasicHandshakeStream(std::move(connection), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14804 | using_proxy); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14805 | } |
| 14806 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14807 | WebSocketHandshakeStreamBase* CreateSpdyStream( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14808 | const base::WeakPtr<SpdySession>& session, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 14809 | bool use_relative_url) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14810 | NOTREACHED(); |
| 14811 | return NULL; |
| 14812 | }; |
| 14813 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14814 | ~FakeWebSocketStreamCreateHelper() override {} |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14815 | |
| 14816 | virtual scoped_ptr<WebSocketStream> Upgrade() { |
| 14817 | NOTREACHED(); |
| 14818 | return scoped_ptr<WebSocketStream>(); |
| 14819 | } |
| 14820 | }; |
| 14821 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14822 | } // namespace |
| 14823 | |
| 14824 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 14825 | // stream request on start. |
| 14826 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14827 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14828 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14829 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14830 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14831 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14832 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14833 | |
| 14834 | ASSERT_TRUE(fake_factory->last_stream_request() == NULL); |
| 14835 | |
| 14836 | HttpRequestInfo request; |
| 14837 | TestCompletionCallback callback; |
| 14838 | EXPECT_EQ(ERR_IO_PENDING, |
| 14839 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14840 | |
| 14841 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14842 | fake_factory->last_stream_request(); |
| 14843 | ASSERT_TRUE(fake_request != NULL); |
| 14844 | EXPECT_EQ(LOW, fake_request->priority()); |
| 14845 | } |
| 14846 | |
| 14847 | // Make sure that HttpNetworkTransaction passes on its priority |
| 14848 | // updates to its stream request. |
| 14849 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14850 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14851 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14852 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14853 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14854 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14855 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14856 | |
| 14857 | HttpRequestInfo request; |
| 14858 | TestCompletionCallback callback; |
| 14859 | EXPECT_EQ(ERR_IO_PENDING, |
| 14860 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14861 | |
| 14862 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14863 | fake_factory->last_stream_request(); |
| 14864 | ASSERT_TRUE(fake_request != NULL); |
| 14865 | EXPECT_EQ(LOW, fake_request->priority()); |
| 14866 | |
| 14867 | trans.SetPriority(LOWEST); |
| 14868 | ASSERT_TRUE(fake_request != NULL); |
| 14869 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 14870 | } |
| 14871 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14872 | // Make sure that HttpNetworkTransaction passes on its priority |
| 14873 | // updates to its stream. |
| 14874 | TEST_P(HttpNetworkTransactionTest, SetStreamPriority) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14875 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14876 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14877 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14878 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14879 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14880 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14881 | |
| 14882 | HttpRequestInfo request; |
| 14883 | TestCompletionCallback callback; |
| 14884 | EXPECT_EQ(ERR_IO_PENDING, |
| 14885 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14886 | |
| 14887 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14888 | fake_factory->last_stream_request(); |
| 14889 | ASSERT_TRUE(fake_request != NULL); |
| 14890 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
| 14891 | ASSERT_TRUE(fake_stream != NULL); |
| 14892 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 14893 | |
| 14894 | trans.SetPriority(LOWEST); |
| 14895 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 14896 | } |
| 14897 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14898 | TEST_P(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
| 14899 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 14900 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 14901 | // that the different schemes work. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14902 | std::string test_cases[] = {"ws://www.example.org/", |
| 14903 | "wss://www.example.org/"}; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14904 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14905 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14906 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14907 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 14908 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
[email protected] | 0191b51c | 2013-11-18 10:55:23 | [diff] [blame] | 14909 | peer.SetHttpStreamFactoryForWebSocket( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14910 | scoped_ptr<HttpStreamFactory>(fake_factory)); |
| 14911 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14912 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14913 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 14914 | &websocket_stream_create_helper); |
| 14915 | |
| 14916 | HttpRequestInfo request; |
| 14917 | TestCompletionCallback callback; |
| 14918 | request.method = "GET"; |
| 14919 | request.url = GURL(test_cases[i]); |
| 14920 | |
| 14921 | EXPECT_EQ(ERR_IO_PENDING, |
| 14922 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14923 | |
| 14924 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14925 | fake_factory->last_stream_request(); |
| 14926 | ASSERT_TRUE(fake_request != NULL); |
| 14927 | EXPECT_EQ(&websocket_stream_create_helper, |
| 14928 | fake_request->websocket_stream_create_helper()); |
| 14929 | } |
| 14930 | } |
| 14931 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14932 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 14933 | // if the transport socket pool is stalled on the global socket limit. |
| 14934 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
| 14935 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 14936 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14937 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 14938 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14939 | |
| 14940 | // Set up SSL request. |
| 14941 | |
| 14942 | HttpRequestInfo ssl_request; |
| 14943 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14944 | ssl_request.url = GURL("https://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14945 | |
| 14946 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14947 | MockWrite( |
| 14948 | "GET / HTTP/1.1\r\n" |
| 14949 | "Host: www.example.org\r\n" |
| 14950 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14951 | }; |
| 14952 | MockRead ssl_reads[] = { |
| 14953 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14954 | MockRead("Content-Length: 11\r\n\r\n"), |
| 14955 | MockRead("hello world"), |
| 14956 | MockRead(SYNCHRONOUS, OK), |
| 14957 | }; |
| 14958 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 14959 | ssl_writes, arraysize(ssl_writes)); |
| 14960 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 14961 | |
| 14962 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14963 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14964 | |
| 14965 | // Set up HTTP request. |
| 14966 | |
| 14967 | HttpRequestInfo http_request; |
| 14968 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14969 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14970 | |
| 14971 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14972 | MockWrite( |
| 14973 | "GET / HTTP/1.1\r\n" |
| 14974 | "Host: www.example.org\r\n" |
| 14975 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14976 | }; |
| 14977 | MockRead http_reads[] = { |
| 14978 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14979 | MockRead("Content-Length: 7\r\n\r\n"), |
| 14980 | MockRead("falafel"), |
| 14981 | MockRead(SYNCHRONOUS, OK), |
| 14982 | }; |
| 14983 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14984 | http_writes, arraysize(http_writes)); |
| 14985 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14986 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14987 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14988 | |
| 14989 | // Start the SSL request. |
| 14990 | TestCompletionCallback ssl_callback; |
| 14991 | scoped_ptr<HttpTransaction> ssl_trans( |
| 14992 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14993 | ASSERT_EQ(ERR_IO_PENDING, |
| 14994 | ssl_trans->Start(&ssl_request, ssl_callback.callback(), |
| 14995 | BoundNetLog())); |
| 14996 | |
| 14997 | // Start the HTTP request. Pool should stall. |
| 14998 | TestCompletionCallback http_callback; |
| 14999 | scoped_ptr<HttpTransaction> http_trans( |
| 15000 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15001 | ASSERT_EQ(ERR_IO_PENDING, |
| 15002 | http_trans->Start(&http_request, http_callback.callback(), |
| 15003 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15004 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15005 | |
| 15006 | // Wait for response from SSL request. |
| 15007 | ASSERT_EQ(OK, ssl_callback.WaitForResult()); |
| 15008 | std::string response_data; |
| 15009 | ASSERT_EQ(OK, ReadTransaction(ssl_trans.get(), &response_data)); |
| 15010 | EXPECT_EQ("hello world", response_data); |
| 15011 | |
| 15012 | // The SSL socket should automatically be closed, so the HTTP request can |
| 15013 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15014 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 15015 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15016 | |
| 15017 | // The HTTP request can now complete. |
| 15018 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 15019 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 15020 | EXPECT_EQ("falafel", response_data); |
| 15021 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15022 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15023 | } |
| 15024 | |
| 15025 | // Tests that when a SSL connection is established but there's no corresponding |
| 15026 | // request that needs it, the new socket is closed if the transport socket pool |
| 15027 | // is stalled on the global socket limit. |
| 15028 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
| 15029 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15030 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15031 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15032 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15033 | |
| 15034 | // Set up an ssl request. |
| 15035 | |
| 15036 | HttpRequestInfo ssl_request; |
| 15037 | ssl_request.method = "GET"; |
| 15038 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 15039 | |
| 15040 | // No data will be sent on the SSL socket. |
| 15041 | StaticSocketDataProvider ssl_data; |
| 15042 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 15043 | |
| 15044 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15045 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15046 | |
| 15047 | // Set up HTTP request. |
| 15048 | |
| 15049 | HttpRequestInfo http_request; |
| 15050 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15051 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15052 | |
| 15053 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15054 | MockWrite( |
| 15055 | "GET / HTTP/1.1\r\n" |
| 15056 | "Host: www.example.org\r\n" |
| 15057 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15058 | }; |
| 15059 | MockRead http_reads[] = { |
| 15060 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15061 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15062 | MockRead("falafel"), |
| 15063 | MockRead(SYNCHRONOUS, OK), |
| 15064 | }; |
| 15065 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15066 | http_writes, arraysize(http_writes)); |
| 15067 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15068 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15069 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15070 | |
| 15071 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 15072 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15073 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
| 15074 | SSLConfig ssl_config; |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15075 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
mmenke | d1205bd | 2015-07-15 22:26:35 | [diff] [blame] | 15076 | http_stream_factory->PreconnectStreams(1, ssl_request, ssl_config, |
| 15077 | ssl_config); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15078 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15079 | |
| 15080 | // Start the HTTP request. Pool should stall. |
| 15081 | TestCompletionCallback http_callback; |
| 15082 | scoped_ptr<HttpTransaction> http_trans( |
| 15083 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15084 | ASSERT_EQ(ERR_IO_PENDING, |
| 15085 | http_trans->Start(&http_request, http_callback.callback(), |
| 15086 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15087 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15088 | |
| 15089 | // The SSL connection will automatically be closed once the connection is |
| 15090 | // established, to let the HTTP request start. |
| 15091 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 15092 | std::string response_data; |
| 15093 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 15094 | EXPECT_EQ("falafel", response_data); |
| 15095 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15096 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15097 | } |
| 15098 | |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15099 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15100 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15101 | element_readers.push_back( |
| 15102 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15103 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15104 | |
| 15105 | HttpRequestInfo request; |
| 15106 | request.method = "POST"; |
| 15107 | request.url = GURL("http://www.foo.com/"); |
| 15108 | request.upload_data_stream = &upload_data_stream; |
| 15109 | request.load_flags = 0; |
| 15110 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15111 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15112 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15113 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15114 | // Send headers successfully, but get an error while sending the body. |
| 15115 | MockWrite data_writes[] = { |
| 15116 | MockWrite("POST / HTTP/1.1\r\n" |
| 15117 | "Host: www.foo.com\r\n" |
| 15118 | "Connection: keep-alive\r\n" |
| 15119 | "Content-Length: 3\r\n\r\n"), |
| 15120 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15121 | }; |
| 15122 | |
| 15123 | MockRead data_reads[] = { |
| 15124 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15125 | MockRead("hello world"), |
| 15126 | MockRead(SYNCHRONOUS, OK), |
| 15127 | }; |
| 15128 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15129 | arraysize(data_writes)); |
| 15130 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15131 | |
| 15132 | TestCompletionCallback callback; |
| 15133 | |
| 15134 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15135 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15136 | |
| 15137 | rv = callback.WaitForResult(); |
| 15138 | EXPECT_EQ(OK, rv); |
| 15139 | |
| 15140 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15141 | ASSERT_TRUE(response != NULL); |
| 15142 | |
| 15143 | EXPECT_TRUE(response->headers.get() != NULL); |
| 15144 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15145 | |
| 15146 | std::string response_data; |
| 15147 | rv = ReadTransaction(trans.get(), &response_data); |
| 15148 | EXPECT_EQ(OK, rv); |
| 15149 | EXPECT_EQ("hello world", response_data); |
| 15150 | } |
| 15151 | |
| 15152 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 15153 | // response from a server that rejected a POST with a CONNECTION_RESET. |
| 15154 | TEST_P(HttpNetworkTransactionTest, |
| 15155 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15156 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15157 | MockWrite data_writes[] = { |
| 15158 | MockWrite("GET / HTTP/1.1\r\n" |
| 15159 | "Host: www.foo.com\r\n" |
| 15160 | "Connection: keep-alive\r\n\r\n"), |
| 15161 | MockWrite("POST / HTTP/1.1\r\n" |
| 15162 | "Host: www.foo.com\r\n" |
| 15163 | "Connection: keep-alive\r\n" |
| 15164 | "Content-Length: 3\r\n\r\n"), |
| 15165 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15166 | }; |
| 15167 | |
| 15168 | MockRead data_reads[] = { |
| 15169 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 15170 | "Content-Length: 14\r\n\r\n"), |
| 15171 | MockRead("first response"), |
| 15172 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 15173 | "Content-Length: 15\r\n\r\n"), |
| 15174 | MockRead("second response"), |
| 15175 | MockRead(SYNCHRONOUS, OK), |
| 15176 | }; |
| 15177 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15178 | arraysize(data_writes)); |
| 15179 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15180 | |
| 15181 | TestCompletionCallback callback; |
| 15182 | HttpRequestInfo request1; |
| 15183 | request1.method = "GET"; |
| 15184 | request1.url = GURL("http://www.foo.com/"); |
| 15185 | request1.load_flags = 0; |
| 15186 | |
| 15187 | scoped_ptr<HttpTransaction> trans1( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15188 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15189 | int rv = trans1->Start(&request1, callback.callback(), BoundNetLog()); |
| 15190 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15191 | |
| 15192 | rv = callback.WaitForResult(); |
| 15193 | EXPECT_EQ(OK, rv); |
| 15194 | |
| 15195 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 15196 | ASSERT_TRUE(response1 != NULL); |
| 15197 | |
| 15198 | EXPECT_TRUE(response1->headers.get() != NULL); |
| 15199 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 15200 | |
| 15201 | std::string response_data1; |
| 15202 | rv = ReadTransaction(trans1.get(), &response_data1); |
| 15203 | EXPECT_EQ(OK, rv); |
| 15204 | EXPECT_EQ("first response", response_data1); |
| 15205 | // Delete the transaction to release the socket back into the socket pool. |
| 15206 | trans1.reset(); |
| 15207 | |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15208 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15209 | element_readers.push_back( |
| 15210 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15211 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15212 | |
| 15213 | HttpRequestInfo request2; |
| 15214 | request2.method = "POST"; |
| 15215 | request2.url = GURL("http://www.foo.com/"); |
| 15216 | request2.upload_data_stream = &upload_data_stream; |
| 15217 | request2.load_flags = 0; |
| 15218 | |
| 15219 | scoped_ptr<HttpTransaction> trans2( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15220 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15221 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 15222 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15223 | |
| 15224 | rv = callback.WaitForResult(); |
| 15225 | EXPECT_EQ(OK, rv); |
| 15226 | |
| 15227 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 15228 | ASSERT_TRUE(response2 != NULL); |
| 15229 | |
| 15230 | EXPECT_TRUE(response2->headers.get() != NULL); |
| 15231 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 15232 | |
| 15233 | std::string response_data2; |
| 15234 | rv = ReadTransaction(trans2.get(), &response_data2); |
| 15235 | EXPECT_EQ(OK, rv); |
| 15236 | EXPECT_EQ("second response", response_data2); |
| 15237 | } |
| 15238 | |
| 15239 | TEST_P(HttpNetworkTransactionTest, |
| 15240 | PostReadsErrorResponseAfterResetPartialBodySent) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15241 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15242 | element_readers.push_back( |
| 15243 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15244 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15245 | |
| 15246 | HttpRequestInfo request; |
| 15247 | request.method = "POST"; |
| 15248 | request.url = GURL("http://www.foo.com/"); |
| 15249 | request.upload_data_stream = &upload_data_stream; |
| 15250 | request.load_flags = 0; |
| 15251 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15252 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15253 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15254 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15255 | // Send headers successfully, but get an error while sending the body. |
| 15256 | MockWrite data_writes[] = { |
| 15257 | MockWrite("POST / HTTP/1.1\r\n" |
| 15258 | "Host: www.foo.com\r\n" |
| 15259 | "Connection: keep-alive\r\n" |
| 15260 | "Content-Length: 3\r\n\r\n" |
| 15261 | "fo"), |
| 15262 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15263 | }; |
| 15264 | |
| 15265 | MockRead data_reads[] = { |
| 15266 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15267 | MockRead("hello world"), |
| 15268 | MockRead(SYNCHRONOUS, OK), |
| 15269 | }; |
| 15270 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15271 | arraysize(data_writes)); |
| 15272 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15273 | |
| 15274 | TestCompletionCallback callback; |
| 15275 | |
| 15276 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15277 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15278 | |
| 15279 | rv = callback.WaitForResult(); |
| 15280 | EXPECT_EQ(OK, rv); |
| 15281 | |
| 15282 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15283 | ASSERT_TRUE(response != NULL); |
| 15284 | |
| 15285 | EXPECT_TRUE(response->headers.get() != NULL); |
| 15286 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15287 | |
| 15288 | std::string response_data; |
| 15289 | rv = ReadTransaction(trans.get(), &response_data); |
| 15290 | EXPECT_EQ(OK, rv); |
| 15291 | EXPECT_EQ("hello world", response_data); |
| 15292 | } |
| 15293 | |
| 15294 | // This tests the more common case than the previous test, where headers and |
| 15295 | // body are not merged into a single request. |
| 15296 | TEST_P(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 15297 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15298 | |
| 15299 | HttpRequestInfo request; |
| 15300 | request.method = "POST"; |
| 15301 | request.url = GURL("http://www.foo.com/"); |
| 15302 | request.upload_data_stream = &upload_data_stream; |
| 15303 | request.load_flags = 0; |
| 15304 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15305 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15306 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15307 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15308 | // Send headers successfully, but get an error while sending the body. |
| 15309 | MockWrite data_writes[] = { |
| 15310 | MockWrite("POST / HTTP/1.1\r\n" |
| 15311 | "Host: www.foo.com\r\n" |
| 15312 | "Connection: keep-alive\r\n" |
| 15313 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 15314 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15315 | }; |
| 15316 | |
| 15317 | MockRead data_reads[] = { |
| 15318 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15319 | MockRead("hello world"), |
| 15320 | MockRead(SYNCHRONOUS, OK), |
| 15321 | }; |
| 15322 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15323 | arraysize(data_writes)); |
| 15324 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15325 | |
| 15326 | TestCompletionCallback callback; |
| 15327 | |
| 15328 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15329 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15330 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 15331 | // they can't be merged with the body in a single send. Not currently |
| 15332 | // necessary since a chunked body is never merged with headers, but this makes |
| 15333 | // the test more future proof. |
| 15334 | base::RunLoop().RunUntilIdle(); |
| 15335 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 15336 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15337 | |
| 15338 | rv = callback.WaitForResult(); |
| 15339 | EXPECT_EQ(OK, rv); |
| 15340 | |
| 15341 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15342 | ASSERT_TRUE(response != NULL); |
| 15343 | |
| 15344 | EXPECT_TRUE(response->headers.get() != NULL); |
| 15345 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15346 | |
| 15347 | std::string response_data; |
| 15348 | rv = ReadTransaction(trans.get(), &response_data); |
| 15349 | EXPECT_EQ(OK, rv); |
| 15350 | EXPECT_EQ("hello world", response_data); |
| 15351 | } |
| 15352 | |
| 15353 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15354 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15355 | element_readers.push_back( |
| 15356 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15357 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15358 | |
| 15359 | HttpRequestInfo request; |
| 15360 | request.method = "POST"; |
| 15361 | request.url = GURL("http://www.foo.com/"); |
| 15362 | request.upload_data_stream = &upload_data_stream; |
| 15363 | request.load_flags = 0; |
| 15364 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15365 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15366 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15367 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15368 | |
| 15369 | MockWrite data_writes[] = { |
| 15370 | MockWrite("POST / HTTP/1.1\r\n" |
| 15371 | "Host: www.foo.com\r\n" |
| 15372 | "Connection: keep-alive\r\n" |
| 15373 | "Content-Length: 3\r\n\r\n"), |
| 15374 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15375 | }; |
| 15376 | |
| 15377 | MockRead data_reads[] = { |
| 15378 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 15379 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15380 | MockRead("hello world"), |
| 15381 | MockRead(SYNCHRONOUS, OK), |
| 15382 | }; |
| 15383 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15384 | arraysize(data_writes)); |
| 15385 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15386 | |
| 15387 | TestCompletionCallback callback; |
| 15388 | |
| 15389 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15390 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15391 | |
| 15392 | rv = callback.WaitForResult(); |
| 15393 | EXPECT_EQ(OK, rv); |
| 15394 | |
| 15395 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15396 | ASSERT_TRUE(response != NULL); |
| 15397 | |
| 15398 | EXPECT_TRUE(response->headers.get() != NULL); |
| 15399 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15400 | |
| 15401 | std::string response_data; |
| 15402 | rv = ReadTransaction(trans.get(), &response_data); |
| 15403 | EXPECT_EQ(OK, rv); |
| 15404 | EXPECT_EQ("hello world", response_data); |
| 15405 | } |
| 15406 | |
| 15407 | TEST_P(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15408 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15409 | element_readers.push_back( |
| 15410 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15411 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15412 | |
| 15413 | HttpRequestInfo request; |
| 15414 | request.method = "POST"; |
| 15415 | request.url = GURL("http://www.foo.com/"); |
| 15416 | request.upload_data_stream = &upload_data_stream; |
| 15417 | request.load_flags = 0; |
| 15418 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15419 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15420 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15421 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15422 | // Send headers successfully, but get an error while sending the body. |
| 15423 | MockWrite data_writes[] = { |
| 15424 | MockWrite("POST / HTTP/1.1\r\n" |
| 15425 | "Host: www.foo.com\r\n" |
| 15426 | "Connection: keep-alive\r\n" |
| 15427 | "Content-Length: 3\r\n\r\n"), |
| 15428 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15429 | }; |
| 15430 | |
| 15431 | MockRead data_reads[] = { |
| 15432 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 15433 | MockRead("hello world"), |
| 15434 | MockRead(SYNCHRONOUS, OK), |
| 15435 | }; |
| 15436 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15437 | arraysize(data_writes)); |
| 15438 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15439 | |
| 15440 | TestCompletionCallback callback; |
| 15441 | |
| 15442 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15443 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15444 | |
| 15445 | rv = callback.WaitForResult(); |
| 15446 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15447 | } |
| 15448 | |
| 15449 | TEST_P(HttpNetworkTransactionTest, |
| 15450 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15451 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15452 | element_readers.push_back( |
| 15453 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15454 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15455 | |
| 15456 | HttpRequestInfo request; |
| 15457 | request.method = "POST"; |
| 15458 | request.url = GURL("http://www.foo.com/"); |
| 15459 | request.upload_data_stream = &upload_data_stream; |
| 15460 | request.load_flags = 0; |
| 15461 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15462 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15463 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15464 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15465 | // Send headers successfully, but get an error while sending the body. |
| 15466 | MockWrite data_writes[] = { |
| 15467 | MockWrite("POST / HTTP/1.1\r\n" |
| 15468 | "Host: www.foo.com\r\n" |
| 15469 | "Connection: keep-alive\r\n" |
| 15470 | "Content-Length: 3\r\n\r\n"), |
| 15471 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15472 | }; |
| 15473 | |
| 15474 | MockRead data_reads[] = { |
| 15475 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 15476 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 15477 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 15478 | MockRead("Content-Length: 0\r\n\r\n"), |
| 15479 | MockRead(SYNCHRONOUS, OK), |
| 15480 | }; |
| 15481 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15482 | arraysize(data_writes)); |
| 15483 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15484 | |
| 15485 | TestCompletionCallback callback; |
| 15486 | |
| 15487 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15488 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15489 | |
| 15490 | rv = callback.WaitForResult(); |
| 15491 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15492 | } |
| 15493 | |
| 15494 | TEST_P(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15495 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15496 | element_readers.push_back( |
| 15497 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15498 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15499 | |
| 15500 | HttpRequestInfo request; |
| 15501 | request.method = "POST"; |
| 15502 | request.url = GURL("http://www.foo.com/"); |
| 15503 | request.upload_data_stream = &upload_data_stream; |
| 15504 | request.load_flags = 0; |
| 15505 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15506 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15507 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15508 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15509 | // Send headers successfully, but get an error while sending the body. |
| 15510 | MockWrite data_writes[] = { |
| 15511 | MockWrite("POST / HTTP/1.1\r\n" |
| 15512 | "Host: www.foo.com\r\n" |
| 15513 | "Connection: keep-alive\r\n" |
| 15514 | "Content-Length: 3\r\n\r\n"), |
| 15515 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15516 | }; |
| 15517 | |
| 15518 | MockRead data_reads[] = { |
| 15519 | MockRead("HTTP 0.9 rocks!"), |
| 15520 | MockRead(SYNCHRONOUS, OK), |
| 15521 | }; |
| 15522 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15523 | arraysize(data_writes)); |
| 15524 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15525 | |
| 15526 | TestCompletionCallback callback; |
| 15527 | |
| 15528 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15529 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15530 | |
| 15531 | rv = callback.WaitForResult(); |
| 15532 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15533 | } |
| 15534 | |
| 15535 | TEST_P(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15536 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15537 | element_readers.push_back( |
| 15538 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15539 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15540 | |
| 15541 | HttpRequestInfo request; |
| 15542 | request.method = "POST"; |
| 15543 | request.url = GURL("http://www.foo.com/"); |
| 15544 | request.upload_data_stream = &upload_data_stream; |
| 15545 | request.load_flags = 0; |
| 15546 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15547 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15548 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15549 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15550 | // Send headers successfully, but get an error while sending the body. |
| 15551 | MockWrite data_writes[] = { |
| 15552 | MockWrite("POST / HTTP/1.1\r\n" |
| 15553 | "Host: www.foo.com\r\n" |
| 15554 | "Connection: keep-alive\r\n" |
| 15555 | "Content-Length: 3\r\n\r\n"), |
| 15556 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15557 | }; |
| 15558 | |
| 15559 | MockRead data_reads[] = { |
| 15560 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 15561 | MockRead(SYNCHRONOUS, OK), |
| 15562 | }; |
| 15563 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15564 | arraysize(data_writes)); |
| 15565 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15566 | |
| 15567 | TestCompletionCallback callback; |
| 15568 | |
| 15569 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15570 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15571 | |
| 15572 | rv = callback.WaitForResult(); |
| 15573 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15574 | } |
| 15575 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15576 | // Verify that proxy headers are not sent to the destination server when |
| 15577 | // establishing a tunnel for a secure WebSocket connection. |
| 15578 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
| 15579 | HttpRequestInfo request; |
| 15580 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15581 | request.url = GURL("wss://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15582 | AddWebSocketHeaders(&request.extra_headers); |
| 15583 | |
| 15584 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 15585 | session_deps_.proxy_service = |
| 15586 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15587 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15588 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15589 | |
| 15590 | // Since a proxy is configured, try to establish a tunnel. |
| 15591 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15592 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15593 | "Host: www.example.org:443\r\n" |
| 15594 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15595 | |
| 15596 | // After calling trans->RestartWithAuth(), this is the request we should |
| 15597 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15598 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15599 | "Host: www.example.org:443\r\n" |
| 15600 | "Proxy-Connection: keep-alive\r\n" |
| 15601 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15602 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15603 | MockWrite("GET / HTTP/1.1\r\n" |
| 15604 | "Host: www.example.org\r\n" |
| 15605 | "Connection: Upgrade\r\n" |
| 15606 | "Upgrade: websocket\r\n" |
| 15607 | "Origin: http://www.example.org\r\n" |
| 15608 | "Sec-WebSocket-Version: 13\r\n" |
| 15609 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15610 | }; |
| 15611 | |
| 15612 | // The proxy responds to the connect with a 407, using a persistent |
| 15613 | // connection. |
| 15614 | MockRead data_reads[] = { |
| 15615 | // No credentials. |
| 15616 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 15617 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 15618 | MockRead("Content-Length: 0\r\n"), |
| 15619 | MockRead("Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15620 | |
| 15621 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 15622 | |
| 15623 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 15624 | MockRead("Upgrade: websocket\r\n"), |
| 15625 | MockRead("Connection: Upgrade\r\n"), |
| 15626 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 15627 | }; |
| 15628 | |
| 15629 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15630 | arraysize(data_writes)); |
| 15631 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15632 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15633 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15634 | |
| 15635 | scoped_ptr<HttpTransaction> trans( |
| 15636 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15637 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 15638 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 15639 | &websocket_stream_create_helper); |
| 15640 | |
| 15641 | { |
| 15642 | TestCompletionCallback callback; |
| 15643 | |
| 15644 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15645 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15646 | |
| 15647 | rv = callback.WaitForResult(); |
| 15648 | EXPECT_EQ(OK, rv); |
| 15649 | } |
| 15650 | |
| 15651 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15652 | ASSERT_TRUE(response); |
| 15653 | ASSERT_TRUE(response->headers.get()); |
| 15654 | EXPECT_EQ(407, response->headers->response_code()); |
| 15655 | |
| 15656 | { |
| 15657 | TestCompletionCallback callback; |
| 15658 | |
| 15659 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 15660 | callback.callback()); |
| 15661 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15662 | |
| 15663 | rv = callback.WaitForResult(); |
| 15664 | EXPECT_EQ(OK, rv); |
| 15665 | } |
| 15666 | |
| 15667 | response = trans->GetResponseInfo(); |
| 15668 | ASSERT_TRUE(response); |
| 15669 | ASSERT_TRUE(response->headers.get()); |
| 15670 | |
| 15671 | EXPECT_EQ(101, response->headers->response_code()); |
| 15672 | |
| 15673 | trans.reset(); |
| 15674 | session->CloseAllConnections(); |
| 15675 | } |
| 15676 | |
| 15677 | // Verify that proxy headers are not sent to the destination server when |
| 15678 | // establishing a tunnel for an insecure WebSocket connection. |
| 15679 | // This requires the authentication info to be injected into the auth cache |
| 15680 | // due to crbug.com/395064 |
| 15681 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
| 15682 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
| 15683 | HttpRequestInfo request; |
| 15684 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15685 | request.url = GURL("ws://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15686 | AddWebSocketHeaders(&request.extra_headers); |
| 15687 | |
| 15688 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 15689 | session_deps_.proxy_service = |
| 15690 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15691 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15692 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15693 | |
| 15694 | MockWrite data_writes[] = { |
| 15695 | // Try to establish a tunnel for the WebSocket connection, with |
| 15696 | // credentials. Because WebSockets have a separate set of socket pools, |
| 15697 | // they cannot and will not use the same TCP/IP connection as the |
| 15698 | // preflight HTTP request. |
| 15699 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15700 | "CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 15701 | "Host: www.example.org:80\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15702 | "Proxy-Connection: keep-alive\r\n" |
| 15703 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 15704 | |
| 15705 | MockWrite( |
| 15706 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15707 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15708 | "Connection: Upgrade\r\n" |
| 15709 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15710 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15711 | "Sec-WebSocket-Version: 13\r\n" |
| 15712 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 15713 | }; |
| 15714 | |
| 15715 | MockRead data_reads[] = { |
| 15716 | // HTTP CONNECT with credentials. |
| 15717 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 15718 | |
| 15719 | // WebSocket connection established inside tunnel. |
| 15720 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 15721 | MockRead("Upgrade: websocket\r\n"), |
| 15722 | MockRead("Connection: Upgrade\r\n"), |
| 15723 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 15724 | }; |
| 15725 | |
| 15726 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15727 | arraysize(data_writes)); |
| 15728 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15729 | |
| 15730 | session->http_auth_cache()->Add( |
| 15731 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 15732 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 15733 | |
| 15734 | scoped_ptr<HttpTransaction> trans( |
| 15735 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15736 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 15737 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 15738 | &websocket_stream_create_helper); |
| 15739 | |
| 15740 | TestCompletionCallback callback; |
| 15741 | |
| 15742 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15743 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15744 | |
| 15745 | rv = callback.WaitForResult(); |
| 15746 | EXPECT_EQ(OK, rv); |
| 15747 | |
| 15748 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15749 | ASSERT_TRUE(response); |
| 15750 | ASSERT_TRUE(response->headers.get()); |
| 15751 | |
| 15752 | EXPECT_EQ(101, response->headers->response_code()); |
| 15753 | |
| 15754 | trans.reset(); |
| 15755 | session->CloseAllConnections(); |
| 15756 | } |
| 15757 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15758 | TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15759 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15760 | element_readers.push_back( |
| 15761 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15762 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15763 | |
| 15764 | HttpRequestInfo request; |
| 15765 | request.method = "POST"; |
| 15766 | request.url = GURL("http://www.foo.com/"); |
| 15767 | request.upload_data_stream = &upload_data_stream; |
| 15768 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15769 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15770 | scoped_ptr<HttpTransaction> trans( |
| 15771 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15772 | MockWrite data_writes[] = { |
| 15773 | MockWrite("POST / HTTP/1.1\r\n" |
| 15774 | "Host: www.foo.com\r\n" |
| 15775 | "Connection: keep-alive\r\n" |
| 15776 | "Content-Length: 3\r\n\r\n"), |
| 15777 | MockWrite("foo"), |
| 15778 | }; |
| 15779 | |
| 15780 | MockRead data_reads[] = { |
| 15781 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 15782 | MockRead(SYNCHRONOUS, OK), |
| 15783 | }; |
| 15784 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15785 | arraysize(data_writes)); |
| 15786 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15787 | |
| 15788 | TestCompletionCallback callback; |
| 15789 | |
| 15790 | EXPECT_EQ(ERR_IO_PENDING, |
| 15791 | trans->Start(&request, callback.callback(), BoundNetLog())); |
| 15792 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 15793 | |
| 15794 | std::string response_data; |
| 15795 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 15796 | |
| 15797 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 15798 | trans->GetTotalSentBytes()); |
| 15799 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 15800 | trans->GetTotalReceivedBytes()); |
| 15801 | } |
| 15802 | |
| 15803 | TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15804 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15805 | element_readers.push_back( |
| 15806 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15807 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15808 | |
| 15809 | HttpRequestInfo request; |
| 15810 | request.method = "POST"; |
| 15811 | request.url = GURL("http://www.foo.com/"); |
| 15812 | request.upload_data_stream = &upload_data_stream; |
| 15813 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15814 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15815 | scoped_ptr<HttpTransaction> trans( |
| 15816 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15817 | MockWrite data_writes[] = { |
| 15818 | MockWrite("POST / HTTP/1.1\r\n" |
| 15819 | "Host: www.foo.com\r\n" |
| 15820 | "Connection: keep-alive\r\n" |
| 15821 | "Content-Length: 3\r\n\r\n"), |
| 15822 | MockWrite("foo"), |
| 15823 | }; |
| 15824 | |
| 15825 | MockRead data_reads[] = { |
| 15826 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 15827 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 15828 | MockRead(SYNCHRONOUS, OK), |
| 15829 | }; |
| 15830 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15831 | arraysize(data_writes)); |
| 15832 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15833 | |
| 15834 | TestCompletionCallback callback; |
| 15835 | |
| 15836 | EXPECT_EQ(ERR_IO_PENDING, |
| 15837 | trans->Start(&request, callback.callback(), BoundNetLog())); |
| 15838 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 15839 | |
| 15840 | std::string response_data; |
| 15841 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 15842 | |
| 15843 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 15844 | trans->GetTotalSentBytes()); |
| 15845 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 15846 | trans->GetTotalReceivedBytes()); |
| 15847 | } |
| 15848 | |
| 15849 | TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15850 | ChunkedUploadDataStream upload_data_stream(0); |
| 15851 | |
| 15852 | HttpRequestInfo request; |
| 15853 | request.method = "POST"; |
| 15854 | request.url = GURL("http://www.foo.com/"); |
| 15855 | request.upload_data_stream = &upload_data_stream; |
| 15856 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15857 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15858 | scoped_ptr<HttpTransaction> trans( |
| 15859 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15860 | // Send headers successfully, but get an error while sending the body. |
| 15861 | MockWrite data_writes[] = { |
| 15862 | MockWrite("POST / HTTP/1.1\r\n" |
| 15863 | "Host: www.foo.com\r\n" |
| 15864 | "Connection: keep-alive\r\n" |
| 15865 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 15866 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 15867 | }; |
| 15868 | |
| 15869 | MockRead data_reads[] = { |
| 15870 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 15871 | MockRead(SYNCHRONOUS, OK), |
| 15872 | }; |
| 15873 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15874 | arraysize(data_writes)); |
| 15875 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15876 | |
| 15877 | TestCompletionCallback callback; |
| 15878 | |
| 15879 | EXPECT_EQ(ERR_IO_PENDING, |
| 15880 | trans->Start(&request, callback.callback(), BoundNetLog())); |
| 15881 | |
| 15882 | base::RunLoop().RunUntilIdle(); |
| 15883 | upload_data_stream.AppendData("f", 1, false); |
| 15884 | |
| 15885 | base::RunLoop().RunUntilIdle(); |
| 15886 | upload_data_stream.AppendData("oo", 2, true); |
| 15887 | |
| 15888 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 15889 | |
| 15890 | std::string response_data; |
| 15891 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 15892 | |
| 15893 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 15894 | trans->GetTotalSentBytes()); |
| 15895 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 15896 | trans->GetTotalReceivedBytes()); |
| 15897 | } |
| 15898 | |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 15899 | TEST_P(HttpNetworkTransactionTest, EnableNPN) { |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 15900 | session_deps_.enable_npn = true; |
| 15901 | |
| 15902 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15903 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 15904 | |
| 15905 | EXPECT_THAT(trans.server_ssl_config_.alpn_protos, |
| 15906 | testing::ElementsAre(kProtoHTTP2, kProtoSPDY31, kProtoHTTP11)); |
| 15907 | EXPECT_THAT(trans.server_ssl_config_.npn_protos, |
| 15908 | testing::ElementsAre(kProtoHTTP2, kProtoSPDY31, kProtoHTTP11)); |
| 15909 | } |
| 15910 | |
| 15911 | TEST_P(HttpNetworkTransactionTest, DisableNPN) { |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 15912 | session_deps_.enable_npn = false; |
| 15913 | |
| 15914 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15915 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 15916 | |
| 15917 | EXPECT_THAT(trans.server_ssl_config_.alpn_protos, |
| 15918 | testing::ElementsAre(kProtoHTTP2, kProtoSPDY31, kProtoHTTP11)); |
| 15919 | EXPECT_TRUE(trans.server_ssl_config_.npn_protos.empty()); |
| 15920 | } |
| 15921 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15922 | #if !defined(OS_IOS) |
| 15923 | TEST_P(HttpNetworkTransactionTest, TokenBindingSpdy) { |
| 15924 | const std::string https_url = "https://www.example.com"; |
| 15925 | HttpRequestInfo request; |
| 15926 | request.url = GURL(https_url); |
| 15927 | request.method = "GET"; |
| 15928 | |
| 15929 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15930 | ssl.token_binding_negotiated = true; |
| 15931 | ssl.token_binding_key_param = TB_PARAM_ECDSAP256; |
| 15932 | ssl.SetNextProto(GetProtocol()); |
| 15933 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15934 | |
| 15935 | scoped_ptr<SpdyFrame> resp( |
| 15936 | spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
| 15937 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 15938 | MockRead reads[] = {CreateMockRead(*resp), CreateMockRead(*body), |
| 15939 | MockRead(ASYNC, ERR_IO_PENDING)}; |
| 15940 | StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); |
| 15941 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15942 | session_deps_.channel_id_service.reset(new ChannelIDService( |
| 15943 | new DefaultChannelIDStore(nullptr), base::ThreadTaskRunnerHandle::Get())); |
| 15944 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15945 | |
| 15946 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 15947 | TestCompletionCallback callback; |
| 15948 | EXPECT_EQ(ERR_IO_PENDING, |
| 15949 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 15950 | base::MessageLoop::current()->RunUntilIdle(); |
| 15951 | |
| 15952 | EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| 15953 | HttpRequestHeaders headers; |
| 15954 | ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
| 15955 | EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 15956 | } |
| 15957 | #endif // !defined(OS_IOS) |
| 15958 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 15959 | } // namespace net |