[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> |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10 | |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11 | #include <limits> |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12 | #include <memory> |
[email protected] | 5285d97 | 2011-10-18 18:56:34 | [diff] [blame] | 13 | #include <string> |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 14 | #include <utility> |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 15 | #include <vector> |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 16 | |
[email protected] | 68bf915 | 2008-09-25 19:47:30 | [diff] [blame] | 17 | #include "base/compiler_specific.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 18 | #include "base/files/file_path.h" |
thestig | d8df033 | 2014-09-04 06:33:29 | [diff] [blame] | 19 | #include "base/files/file_util.h" |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 20 | #include "base/json/json_writer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 21 | #include "base/logging.h" |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 22 | #include "base/macros.h" |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 23 | #include "base/memory/ptr_util.h" |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 24 | #include "base/memory/weak_ptr.h" |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 25 | #include "base/run_loop.h" |
[email protected] | 125ef48 | 2013-06-11 18:32:47 | [diff] [blame] | 26 | #include "base/strings/string_util.h" |
[email protected] | 750b2f3c | 2013-06-07 18:41:05 | [diff] [blame] | 27 | #include "base/strings/utf_string_conversions.h" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 28 | #include "base/test/test_file_util.h" |
gab | f767595f | 2016-05-11 18:50:35 | [diff] [blame] | 29 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 30 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 31 | #include "net/base/chunked_upload_data_stream.h" |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 32 | #include "net/base/completion_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 33 | #include "net/base/elements_upload_data_stream.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 34 | #include "net/base/load_timing_info.h" |
| 35 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 36 | #include "net/base/net_errors.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 37 | #include "net/base/proxy_delegate.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 38 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 39 | #include "net/base/test_completion_callback.h" |
[email protected] | 42fdb45 | 2012-11-01 12:44:40 | [diff] [blame] | 40 | #include "net/base/test_data_directory.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 41 | #include "net/base/test_proxy_delegate.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 42 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 43 | #include "net/base/upload_file_element_reader.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 44 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 45 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 46 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 47 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 48 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 49 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 50 | #include "net/http/http_auth_handler_ntlm.h" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 51 | #include "net/http/http_auth_scheme.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 52 | #include "net/http/http_basic_state.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 53 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 54 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 55 | #include "net/http/http_network_session_peer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 56 | #include "net/http/http_request_headers.h" |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 57 | #include "net/http/http_response_info.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 58 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 59 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 60 | #include "net/http/http_stream_factory.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 61 | #include "net/http/http_stream_parser.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 62 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 63 | #include "net/log/net_log.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 64 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 65 | #include "net/log/test_net_log_entry.h" |
| 66 | #include "net/log/test_net_log_util.h" |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 67 | #include "net/proxy/mock_proxy_resolver.h" |
[email protected] | 51fff29d | 2008-12-19 22:17:53 | [diff] [blame] | 68 | #include "net/proxy/proxy_config_service_fixed.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 69 | #include "net/proxy/proxy_info.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 70 | #include "net/proxy/proxy_resolver.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 71 | #include "net/proxy/proxy_server.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 72 | #include "net/proxy/proxy_service.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 73 | #include "net/socket/client_socket_factory.h" |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 74 | #include "net/socket/client_socket_pool.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 75 | #include "net/socket/client_socket_pool_manager.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 76 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 77 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 78 | #include "net/socket/next_proto.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 79 | #include "net/socket/socket_test_util.h" |
| 80 | #include "net/socket/ssl_client_socket.h" |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 81 | #include "net/spdy/spdy_framer.h" |
| 82 | #include "net/spdy/spdy_session.h" |
| 83 | #include "net/spdy/spdy_session_pool.h" |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 84 | #include "net/spdy/spdy_test_util_common.h" |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 85 | #include "net/ssl/default_channel_id_store.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 86 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 87 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 88 | #include "net/ssl/ssl_config_service_defaults.h" |
| 89 | #include "net/ssl/ssl_info.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 90 | #include "net/ssl/ssl_private_key.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 91 | #include "net/test/cert_test_util.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 92 | #include "net/websockets/websocket_handshake_stream_base.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 93 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 94 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 95 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 96 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 97 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 98 | using base::ASCIIToUTF16; |
| 99 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 100 | //----------------------------------------------------------------------------- |
| 101 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 102 | namespace net { |
| 103 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 104 | namespace { |
| 105 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 106 | enum TestCase { |
| 107 | // Test using the SPDY/3.1 protocol. |
| 108 | kTestCaseSPDY31, |
| 109 | |
| 110 | // Test using the HTTP/2 protocol, without specifying a stream |
| 111 | // dependency based on the RequestPriority. |
| 112 | kTestCaseHTTP2NoPriorityDependencies, |
| 113 | |
| 114 | // Test using the HTTP/2 protocol, specifying a stream |
| 115 | // dependency based on the RequestPriority. |
| 116 | kTestCaseHTTP2PriorityDependencies |
| 117 | }; |
| 118 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 119 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 120 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 121 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 122 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 123 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 124 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 125 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 126 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 127 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 128 | const base::string16 kSecond(ASCIIToUTF16("second")); |
| 129 | const base::string16 kTestingNTLM(ASCIIToUTF16("testing-ntlm")); |
| 130 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 131 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 132 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
| 133 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 134 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 135 | } |
| 136 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 137 | int GetIdleSocketCountInSSLSocketPool(HttpNetworkSession* session) { |
| 138 | return session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 139 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 140 | } |
| 141 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 142 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
| 143 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 144 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 145 | } |
| 146 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 147 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 148 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 149 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 150 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 151 | if (!params) |
| 152 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 153 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 154 | if (!params->GetList("headers", &header_list)) |
| 155 | return false; |
| 156 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 157 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 158 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 159 | return true; |
| 160 | } |
| 161 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 162 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 163 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 164 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 165 | EXPECT_TRUE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 166 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 167 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 168 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 169 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 170 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 171 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 172 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 173 | |
| 174 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 175 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 176 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 177 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 178 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 179 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 180 | } |
| 181 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 182 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 183 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 184 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 185 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 186 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 187 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 188 | |
| 189 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 190 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 191 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 192 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 193 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 194 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 195 | load_timing_info.send_start); |
| 196 | |
| 197 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 198 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 199 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 200 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 201 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 202 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 206 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 207 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 208 | EXPECT_TRUE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 209 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 210 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 211 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 212 | |
| 213 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 214 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 215 | load_timing_info.proxy_resolve_end); |
| 216 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 217 | load_timing_info.send_start); |
| 218 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 219 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 220 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 221 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 222 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 223 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 227 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 228 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 229 | int connect_timing_flags) { |
| 230 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 231 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 232 | |
| 233 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 234 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 235 | load_timing_info.proxy_resolve_end); |
| 236 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 237 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 238 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 239 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 240 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 241 | load_timing_info.send_start); |
| 242 | |
| 243 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 244 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 245 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 246 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 247 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 248 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 249 | } |
| 250 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 251 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 252 | headers->SetHeader("Connection", "Upgrade"); |
| 253 | headers->SetHeader("Upgrade", "websocket"); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 254 | headers->SetHeader("Origin", "http://www.example.org"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 255 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
| 256 | headers->SetHeader("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ=="); |
| 257 | } |
| 258 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 259 | std::unique_ptr<HttpNetworkSession> CreateSession( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 260 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 261 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 262 | } |
| 263 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 264 | } // namespace |
| 265 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 266 | class HttpNetworkTransactionTest |
| 267 | : public PlatformTest, |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 268 | public ::testing::WithParamInterface<TestCase> { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 269 | public: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 270 | virtual ~HttpNetworkTransactionTest() { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 271 | // Important to restore the per-pool limit first, since the pool limit must |
| 272 | // always be greater than group limit, and the tests reduce both limits. |
| 273 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 274 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 275 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 276 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 277 | } |
| 278 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 279 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 280 | HttpNetworkTransactionTest() |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 281 | : spdy_util_(GetProtocol(), GetDependenciesFromPriority()), |
| 282 | session_deps_(GetProtocol()), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 283 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
| 284 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 285 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 286 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
rdsmith | 2e54d1f | 2016-03-21 19:48:17 | [diff] [blame] | 287 | session_deps_.enable_priority_dependencies = GetDependenciesFromPriority(); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 288 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 289 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 290 | struct SimpleGetHelperResult { |
| 291 | int rv; |
| 292 | std::string status_line; |
| 293 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 294 | int64_t total_received_bytes; |
| 295 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 296 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 297 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 298 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 299 | }; |
| 300 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 301 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 302 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 303 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 304 | } |
| 305 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 306 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 307 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 308 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 309 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 310 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 311 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 312 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 313 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 314 | } |
| 315 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 316 | NextProto GetProtocol() const { |
| 317 | return GetParam() == kTestCaseSPDY31 ? kProtoSPDY31 : kProtoHTTP2; |
| 318 | } |
| 319 | |
| 320 | bool GetDependenciesFromPriority() const { |
| 321 | return GetParam() == kTestCaseHTTP2PriorityDependencies; |
| 322 | } |
| 323 | |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 324 | const char* GetAlternateProtocolFromParam() { |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 325 | return AlternateProtocolToString( |
| 326 | AlternateProtocolFromNextProto(GetProtocol())); |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 327 | } |
| 328 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 329 | std::string GetAlternativeServiceHttpHeader() { |
| 330 | return std::string("Alt-Svc: ") + GetAlternateProtocolFromParam() + |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 331 | "=\"www.example.org:443\"\r\n"; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 332 | } |
| 333 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 334 | // Either |write_failure| specifies a write failure or |read_failure| |
| 335 | // specifies a read failure when using a reused socket. In either case, the |
| 336 | // failure should cause the network transaction to resend the request, and the |
| 337 | // other argument should be NULL. |
| 338 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 339 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 340 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 341 | // Either |write_failure| specifies a write failure or |read_failure| |
| 342 | // specifies a read failure when using a reused socket. In either case, the |
| 343 | // failure should cause the network transaction to resend the request, and the |
| 344 | // other argument should be NULL. |
| 345 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 346 | const MockRead* read_failure, |
| 347 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 348 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 349 | SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
| 350 | size_t data_count) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 351 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 352 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 353 | HttpRequestInfo request; |
| 354 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 355 | request.url = GURL("http://www.example.org/"); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 356 | request.load_flags = 0; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 357 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 358 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 359 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 360 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 361 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 362 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 363 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 364 | for (size_t i = 0; i < data_count; ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 365 | session_deps_.socket_factory->AddSocketDataProvider(data[i]); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 366 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 367 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 368 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 369 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 370 | EXPECT_TRUE(log.bound().IsCapturing()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 371 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 372 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 373 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 374 | out.rv = callback.WaitForResult(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 375 | out.total_received_bytes = trans->GetTotalReceivedBytes(); |
| 376 | out.total_sent_bytes = trans->GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 377 | |
| 378 | // Even in the failure cases that use this function, connections are always |
| 379 | // successfully established before the error. |
| 380 | EXPECT_TRUE(trans->GetLoadTimingInfo(&out.load_timing_info)); |
| 381 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 382 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 383 | if (out.rv != OK) |
| 384 | return out; |
| 385 | |
| 386 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 387 | // Can't use ASSERT_* inside helper functions like this, so |
| 388 | // return an error. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 389 | if (!response || !response->headers) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 390 | out.rv = ERR_UNEXPECTED; |
| 391 | return out; |
| 392 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 393 | out.status_line = response->headers->GetStatusLine(); |
| 394 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 395 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 396 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 397 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 398 | bool got_endpoint = |
| 399 | trans->GetRemoteEndpoint(&out.remote_endpoint_after_start); |
| 400 | EXPECT_EQ(got_endpoint, |
| 401 | out.remote_endpoint_after_start.address().size() > 0); |
| 402 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 403 | rv = ReadTransaction(trans.get(), &out.response_data); |
| 404 | EXPECT_EQ(OK, rv); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 405 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 406 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 407 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 408 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 409 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
[email protected] | 169d001 | 2010-05-10 23:20:12 | [diff] [blame] | 410 | NetLog::PHASE_NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 411 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 412 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 413 | NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 414 | NetLog::PHASE_NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 415 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 416 | std::string line; |
| 417 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 418 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 419 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 420 | HttpRequestHeaders request_headers; |
| 421 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 422 | std::string value; |
| 423 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 424 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 425 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 426 | EXPECT_EQ("keep-alive", value); |
| 427 | |
| 428 | std::string response_headers; |
| 429 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 430 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 431 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 432 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 433 | out.total_received_bytes = trans->GetTotalReceivedBytes(); |
| 434 | // The total number of sent bytes should not have changed. |
| 435 | EXPECT_EQ(out.total_sent_bytes, trans->GetTotalSentBytes()); |
| 436 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 437 | trans->GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 438 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 439 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 440 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 441 | SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 442 | size_t reads_count) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 443 | MockWrite data_writes[] = { |
| 444 | MockWrite("GET / HTTP/1.1\r\n" |
| 445 | "Host: www.example.org\r\n" |
| 446 | "Connection: keep-alive\r\n\r\n"), |
| 447 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 448 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 449 | StaticSocketDataProvider reads(data_reads, reads_count, data_writes, |
| 450 | arraysize(data_writes)); |
| 451 | StaticSocketDataProvider* data[] = {&reads}; |
| 452 | SimpleGetHelperResult out = SimpleGetHelperForData(data, 1); |
| 453 | |
| 454 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 455 | out.total_sent_bytes); |
| 456 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 457 | } |
| 458 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 459 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 460 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 461 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 462 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 463 | |
| 464 | void BypassHostCacheOnRefreshHelper(int load_flags); |
| 465 | |
| 466 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 467 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 468 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 469 | SpdySessionDependencies session_deps_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 470 | |
| 471 | // Original socket limits. Some tests set these. Safest to always restore |
| 472 | // them once each test has been run. |
| 473 | int old_max_group_sockets_; |
| 474 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 475 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 476 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 477 | INSTANTIATE_TEST_CASE_P(ProtoPlusDepend, |
bnc | 57685ae6 | 2015-03-10 21:27:20 | [diff] [blame] | 478 | HttpNetworkTransactionTest, |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 479 | testing::Values(kTestCaseSPDY31, |
| 480 | kTestCaseHTTP2NoPriorityDependencies, |
| 481 | kTestCaseHTTP2PriorityDependencies)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 482 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 483 | namespace { |
| 484 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 485 | class BeforeNetworkStartHandler { |
| 486 | public: |
| 487 | explicit BeforeNetworkStartHandler(bool defer) |
| 488 | : defer_on_before_network_start_(defer), |
| 489 | observed_before_network_start_(false) {} |
| 490 | |
| 491 | void OnBeforeNetworkStart(bool* defer) { |
| 492 | *defer = defer_on_before_network_start_; |
| 493 | observed_before_network_start_ = true; |
| 494 | } |
| 495 | |
| 496 | bool observed_before_network_start() const { |
| 497 | return observed_before_network_start_; |
| 498 | } |
| 499 | |
| 500 | private: |
| 501 | const bool defer_on_before_network_start_; |
| 502 | bool observed_before_network_start_; |
| 503 | |
| 504 | DISALLOW_COPY_AND_ASSIGN(BeforeNetworkStartHandler); |
| 505 | }; |
| 506 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame^] | 507 | class BeforeHeadersSentHandler { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 508 | public: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame^] | 509 | BeforeHeadersSentHandler() |
| 510 | : observed_before_headers_sent_with_proxy_(false), |
| 511 | observed_before_headers_sent_(false) {} |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 512 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame^] | 513 | void OnBeforeHeadersSent(const ProxyInfo& proxy_info, |
| 514 | HttpRequestHeaders* request_headers) { |
| 515 | observed_before_headers_sent_ = true; |
| 516 | if (!proxy_info.is_http() && !proxy_info.is_https() && |
| 517 | !proxy_info.is_quic()) { |
| 518 | return; |
| 519 | } |
| 520 | observed_before_headers_sent_with_proxy_ = true; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 521 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 522 | } |
| 523 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame^] | 524 | bool observed_before_headers_sent_with_proxy() const { |
| 525 | return observed_before_headers_sent_with_proxy_; |
| 526 | } |
| 527 | |
| 528 | bool observed_before_headers_sent() const { |
| 529 | return observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | std::string observed_proxy_server_uri() const { |
| 533 | return observed_proxy_server_uri_; |
| 534 | } |
| 535 | |
| 536 | private: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame^] | 537 | bool observed_before_headers_sent_with_proxy_; |
| 538 | bool observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 539 | std::string observed_proxy_server_uri_; |
| 540 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame^] | 541 | DISALLOW_COPY_AND_ASSIGN(BeforeHeadersSentHandler); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 542 | }; |
| 543 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 544 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 545 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 546 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 547 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 548 | const int sizeof_row = strlen(row); |
| 549 | const int num_rows = static_cast<int>( |
| 550 | ceil(static_cast<float>(size) / sizeof_row)); |
| 551 | const int sizeof_data = num_rows * sizeof_row; |
| 552 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 553 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 554 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 555 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 556 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 557 | } |
| 558 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 559 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 560 | // Alternative functions that eliminate randomness and dependency on the local |
| 561 | // host name so that the generated NTLM messages are reproducible. |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 562 | void MockGenerateRandom1(uint8_t* output, size_t n) { |
| 563 | static const uint8_t bytes[] = {0x55, 0x29, 0x66, 0x26, |
| 564 | 0x6b, 0x9c, 0x73, 0x54}; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 565 | static size_t current_byte = 0; |
| 566 | for (size_t i = 0; i < n; ++i) { |
| 567 | output[i] = bytes[current_byte++]; |
| 568 | current_byte %= arraysize(bytes); |
| 569 | } |
| 570 | } |
| 571 | |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 572 | void MockGenerateRandom2(uint8_t* output, size_t n) { |
| 573 | static const uint8_t bytes[] = {0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, |
| 574 | 0x70, 0xa1, 0x4e, 0xe7, 0x87, 0x45, |
| 575 | 0x31, 0x5b, 0xd3, 0x1f}; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 576 | static size_t current_byte = 0; |
| 577 | for (size_t i = 0; i < n; ++i) { |
| 578 | output[i] = bytes[current_byte++]; |
| 579 | current_byte %= arraysize(bytes); |
| 580 | } |
| 581 | } |
| 582 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 583 | std::string MockGetHostName() { |
| 584 | return "WTC-WIN7"; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 585 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 586 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 587 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 588 | template<typename ParentPool> |
| 589 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 590 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 591 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 592 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 593 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 594 | const std::string last_group_name_received() const { |
| 595 | return last_group_name_; |
| 596 | } |
| 597 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 598 | int RequestSocket(const std::string& group_name, |
| 599 | const void* socket_params, |
| 600 | RequestPriority priority, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 601 | ClientSocketPool::RespectLimits respect_limits, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 602 | ClientSocketHandle* handle, |
| 603 | const CompletionCallback& callback, |
| 604 | const BoundNetLog& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 605 | last_group_name_ = group_name; |
| 606 | return ERR_IO_PENDING; |
| 607 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 608 | void CancelRequest(const std::string& group_name, |
| 609 | ClientSocketHandle* handle) override {} |
| 610 | void ReleaseSocket(const std::string& group_name, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 611 | std::unique_ptr<StreamSocket> socket, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 612 | int id) override {} |
| 613 | void CloseIdleSockets() override {} |
| 614 | int IdleSocketCount() const override { return 0; } |
| 615 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 616 | return 0; |
| 617 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 618 | LoadState GetLoadState(const std::string& group_name, |
| 619 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 620 | return LOAD_STATE_IDLE; |
| 621 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 622 | base::TimeDelta ConnectionTimeout() const override { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 623 | return base::TimeDelta(); |
| 624 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 625 | |
| 626 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 627 | std::string last_group_name_; |
| 628 | }; |
| 629 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 630 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 631 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 632 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 633 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 634 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 635 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 636 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 637 | CaptureGroupNameSSLSocketPool; |
| 638 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 639 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 640 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 641 | HostResolver* host_resolver, |
| 642 | CertVerifier* /* cert_verifier */) |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 643 | : ParentPool(0, 0, host_resolver, NULL, NULL, NULL) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 644 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 645 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 646 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 647 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 648 | CertVerifier* /* cert_verifier */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 649 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL) { |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 650 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 651 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 652 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 653 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 654 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 655 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 656 | : SSLClientSocketPool(0, |
| 657 | 0, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 658 | cert_verifier, |
| 659 | NULL, |
| 660 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 661 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 662 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 663 | std::string(), |
| 664 | NULL, |
| 665 | NULL, |
| 666 | NULL, |
| 667 | NULL, |
| 668 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 669 | NULL) { |
| 670 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 671 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 672 | //----------------------------------------------------------------------------- |
| 673 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 674 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 675 | // configured for common cases. |
| 676 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 677 | if (!auth_challenge) |
| 678 | return false; |
| 679 | EXPECT_FALSE(auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 680 | EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 681 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 682 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 683 | return true; |
| 684 | } |
| 685 | |
| 686 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 687 | if (!auth_challenge) |
| 688 | return false; |
| 689 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 690 | EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString()); |
| 691 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 692 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 693 | return true; |
| 694 | } |
| 695 | |
| 696 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 697 | if (!auth_challenge) |
| 698 | return false; |
| 699 | EXPECT_FALSE(auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 700 | EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 701 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 702 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 703 | return true; |
| 704 | } |
| 705 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 706 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 707 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 708 | if (!auth_challenge) |
| 709 | return false; |
| 710 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 711 | EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString()); |
| 712 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 713 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 714 | return true; |
| 715 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 716 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 717 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 718 | } // namespace |
| 719 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 720 | TEST_P(HttpNetworkTransactionTest, Basic) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 721 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 722 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 723 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 724 | } |
| 725 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 726 | TEST_P(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 727 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 728 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 729 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 730 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 731 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 732 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 733 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 734 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 735 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 736 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 737 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 738 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 739 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 740 | |
| 741 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | // Response with no status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 745 | TEST_P(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 746 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 747 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 748 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 749 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 750 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 751 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 752 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 753 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 754 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 755 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 756 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 760 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 761 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 762 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 763 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 764 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 765 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 766 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 767 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 768 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 769 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 770 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 771 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 775 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 776 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 777 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 778 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 779 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 780 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 781 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 782 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 783 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 784 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 785 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 786 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | // 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] | 790 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 791 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 792 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 793 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 794 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 795 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 796 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 797 | EXPECT_EQ(OK, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 798 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 799 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 800 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 801 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 805 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 806 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 807 | MockRead("\n"), |
| 808 | MockRead("\n"), |
| 809 | MockRead("Q"), |
| 810 | MockRead("J"), |
| 811 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 812 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 813 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 814 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 815 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 816 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 817 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 818 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 819 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 820 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | // Close the connection before enough bytes to have a status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 824 | TEST_P(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 825 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 826 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 827 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 828 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 829 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 830 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 831 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 832 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 833 | EXPECT_EQ("HTT", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 834 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 835 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 836 | } |
| 837 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 838 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 839 | // persistent connection. The response should still terminate since a 204 |
| 840 | // cannot have a response body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 841 | TEST_P(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 842 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 843 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 844 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 845 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 846 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 847 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 848 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 849 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 850 | EXPECT_EQ(OK, out.rv); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 851 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 852 | EXPECT_EQ("", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 853 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 854 | int64_t response_size = reads_size - strlen(junk); |
| 855 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 856 | } |
| 857 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 858 | // A simple request using chunked encoding with some extra data after. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 859 | TEST_P(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 860 | std::string final_chunk = "0\r\n\r\n"; |
| 861 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 862 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 863 | MockRead data_reads[] = { |
| 864 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 865 | MockRead("5\r\nHello\r\n"), |
| 866 | MockRead("1\r\n"), |
| 867 | MockRead(" \r\n"), |
| 868 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 869 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 870 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 871 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 872 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 873 | arraysize(data_reads)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 874 | EXPECT_EQ(OK, out.rv); |
| 875 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 876 | EXPECT_EQ("Hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 877 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 878 | int64_t response_size = reads_size - extra_data.size(); |
| 879 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 880 | } |
| 881 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 882 | // Next tests deal with http://crbug.com/56344. |
| 883 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 884 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 885 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 886 | MockRead data_reads[] = { |
| 887 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 888 | MockRead("Content-Length: 10\r\n"), |
| 889 | MockRead("Content-Length: 5\r\n\r\n"), |
| 890 | }; |
| 891 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 892 | arraysize(data_reads)); |
| 893 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 894 | } |
| 895 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 896 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 897 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 898 | MockRead data_reads[] = { |
| 899 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 900 | MockRead("Content-Length: 5\r\n"), |
| 901 | MockRead("Content-Length: 5\r\n\r\n"), |
| 902 | MockRead("Hello"), |
| 903 | }; |
| 904 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 905 | arraysize(data_reads)); |
| 906 | EXPECT_EQ(OK, out.rv); |
| 907 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 908 | EXPECT_EQ("Hello", out.response_data); |
| 909 | } |
| 910 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 911 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 912 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 913 | // More than 2 dupes. |
| 914 | { |
| 915 | MockRead data_reads[] = { |
| 916 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 917 | MockRead("Content-Length: 5\r\n"), |
| 918 | MockRead("Content-Length: 5\r\n"), |
| 919 | MockRead("Content-Length: 5\r\n\r\n"), |
| 920 | MockRead("Hello"), |
| 921 | }; |
| 922 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 923 | arraysize(data_reads)); |
| 924 | EXPECT_EQ(OK, out.rv); |
| 925 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 926 | EXPECT_EQ("Hello", out.response_data); |
| 927 | } |
| 928 | // HTTP/1.0 |
| 929 | { |
| 930 | MockRead data_reads[] = { |
| 931 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 932 | MockRead("Content-Length: 5\r\n"), |
| 933 | MockRead("Content-Length: 5\r\n"), |
| 934 | MockRead("Content-Length: 5\r\n\r\n"), |
| 935 | MockRead("Hello"), |
| 936 | }; |
| 937 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 938 | arraysize(data_reads)); |
| 939 | EXPECT_EQ(OK, out.rv); |
| 940 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 941 | EXPECT_EQ("Hello", out.response_data); |
| 942 | } |
| 943 | // 2 dupes and one mismatched. |
| 944 | { |
| 945 | MockRead data_reads[] = { |
| 946 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 947 | MockRead("Content-Length: 10\r\n"), |
| 948 | MockRead("Content-Length: 10\r\n"), |
| 949 | MockRead("Content-Length: 5\r\n\r\n"), |
| 950 | }; |
| 951 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 952 | arraysize(data_reads)); |
| 953 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 954 | } |
| 955 | } |
| 956 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 957 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 958 | MultipleContentLengthHeadersTransferEncoding) { |
| 959 | MockRead data_reads[] = { |
| 960 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 961 | MockRead("Content-Length: 666\r\n"), |
| 962 | MockRead("Content-Length: 1337\r\n"), |
| 963 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 964 | MockRead("5\r\nHello\r\n"), |
| 965 | MockRead("1\r\n"), |
| 966 | MockRead(" \r\n"), |
| 967 | MockRead("5\r\nworld\r\n"), |
| 968 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 969 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 970 | }; |
| 971 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 972 | arraysize(data_reads)); |
| 973 | EXPECT_EQ(OK, out.rv); |
| 974 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 975 | EXPECT_EQ("Hello world", out.response_data); |
| 976 | } |
| 977 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 978 | // Next tests deal with http://crbug.com/98895. |
| 979 | |
| 980 | // Checks that a single Content-Disposition header results in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 981 | TEST_P(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 982 | MockRead data_reads[] = { |
| 983 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 984 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 985 | MockRead("Content-Length: 5\r\n\r\n"), |
| 986 | MockRead("Hello"), |
| 987 | }; |
| 988 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 989 | arraysize(data_reads)); |
| 990 | EXPECT_EQ(OK, out.rv); |
| 991 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 992 | EXPECT_EQ("Hello", out.response_data); |
| 993 | } |
| 994 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 995 | // Checks that two identical Content-Disposition headers result in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 996 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 997 | TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 998 | MockRead data_reads[] = { |
| 999 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1000 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1001 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1002 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1003 | MockRead("Hello"), |
| 1004 | }; |
| 1005 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1006 | arraysize(data_reads)); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1007 | EXPECT_EQ(OK, out.rv); |
| 1008 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1009 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | // Checks that two distinct Content-Disposition headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1013 | TEST_P(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1014 | MockRead data_reads[] = { |
| 1015 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1016 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1017 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1018 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1019 | MockRead("Hello"), |
| 1020 | }; |
| 1021 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1022 | arraysize(data_reads)); |
| 1023 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION, out.rv); |
| 1024 | } |
| 1025 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1026 | // Checks that two identical Location headers result in no error. |
| 1027 | // Also tests Location header behavior. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1028 | TEST_P(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1029 | MockRead data_reads[] = { |
| 1030 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1031 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1032 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1033 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1034 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1035 | }; |
| 1036 | |
| 1037 | HttpRequestInfo request; |
| 1038 | request.method = "GET"; |
| 1039 | request.url = GURL("http://redirect.com/"); |
| 1040 | request.load_flags = 0; |
| 1041 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1042 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1043 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1044 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1045 | |
| 1046 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1047 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1048 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1049 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1050 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1051 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1052 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1053 | |
| 1054 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 1055 | |
| 1056 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1057 | ASSERT_TRUE(response); |
| 1058 | ASSERT_TRUE(response->headers); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1059 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1060 | std::string url; |
| 1061 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1062 | EXPECT_EQ("http://good.com/", url); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1063 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1064 | } |
| 1065 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1066 | // Checks that two distinct Location headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1067 | TEST_P(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1068 | MockRead data_reads[] = { |
| 1069 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1070 | MockRead("Location: http://good.com/\r\n"), |
| 1071 | MockRead("Location: http://evil.com/\r\n"), |
| 1072 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1073 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1074 | }; |
| 1075 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1076 | arraysize(data_reads)); |
| 1077 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION, out.rv); |
| 1078 | } |
| 1079 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1080 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1081 | // message body (since HEAD has none). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1082 | TEST_P(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1083 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1084 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1085 | request.url = GURL("http://www.example.org/"); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1086 | request.load_flags = 0; |
| 1087 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1088 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1089 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1090 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame^] | 1091 | BeforeHeadersSentHandler headers_handler; |
| 1092 | trans->SetBeforeHeadersSentCallback( |
| 1093 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 1094 | base::Unretained(&headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1095 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1096 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1097 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1098 | "Host: www.example.org\r\n" |
| 1099 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1100 | }; |
| 1101 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1102 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1103 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1104 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1105 | // No response body because the test stops reading here. |
| 1106 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1107 | }; |
| 1108 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1109 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1110 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1111 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1112 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1113 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1114 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1115 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1116 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1117 | |
| 1118 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1119 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1120 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1121 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1122 | ASSERT_TRUE(response); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1123 | |
| 1124 | // Check that the headers got parsed. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1125 | EXPECT_TRUE(response->headers); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1126 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1127 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1128 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame^] | 1129 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 1130 | EXPECT_FALSE(headers_handler.observed_before_headers_sent_with_proxy()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1131 | |
| 1132 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1133 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1134 | bool has_server_header = response->headers->EnumerateHeader( |
| 1135 | &iter, "Server", &server_header); |
| 1136 | EXPECT_TRUE(has_server_header); |
| 1137 | EXPECT_EQ("Blah", server_header); |
| 1138 | |
| 1139 | // Reading should give EOF right away, since there is no message body |
| 1140 | // (despite non-zero content-length). |
| 1141 | std::string response_data; |
| 1142 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1143 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1144 | EXPECT_EQ("", response_data); |
| 1145 | } |
| 1146 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1147 | TEST_P(HttpNetworkTransactionTest, ReuseConnection) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1148 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1149 | |
| 1150 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1151 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1152 | MockRead("hello"), |
| 1153 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1154 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1155 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1156 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1157 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1158 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1159 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1160 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1161 | "hello", "world" |
| 1162 | }; |
| 1163 | |
| 1164 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1165 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1166 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1167 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1168 | request.load_flags = 0; |
| 1169 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1170 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1171 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1172 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1173 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1174 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1175 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1176 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1177 | |
| 1178 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1179 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1180 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1181 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1182 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1183 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1184 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1185 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1186 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1187 | |
| 1188 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1189 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1190 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1191 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1192 | } |
| 1193 | } |
| 1194 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1195 | TEST_P(HttpNetworkTransactionTest, Ignores100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1196 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1197 | element_readers.push_back( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1198 | base::WrapUnique(new UploadBytesElementReader("foo", 3))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1199 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1200 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1201 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1202 | request.method = "POST"; |
| 1203 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1204 | request.upload_data_stream = &upload_data_stream; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1205 | request.load_flags = 0; |
| 1206 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1207 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1208 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1209 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1210 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1211 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1212 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1213 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1214 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1215 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1216 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1217 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1218 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1219 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1220 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1221 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1222 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1223 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1224 | |
| 1225 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1226 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1227 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1228 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1229 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1230 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1231 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1232 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1233 | |
| 1234 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1235 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1236 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1237 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1238 | } |
| 1239 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1240 | // This test is almost the same as Ignores100 above, but the response contains |
| 1241 | // 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] | 1242 | // HTTP/1.1 and the two status headers are read in one read. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1243 | TEST_P(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1244 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1245 | request.method = "GET"; |
| 1246 | request.url = GURL("http://www.foo.com/"); |
| 1247 | request.load_flags = 0; |
| 1248 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1249 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1250 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1251 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1252 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1253 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1254 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1255 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1256 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1257 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1258 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1259 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1260 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1261 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1262 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1263 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1264 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1265 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1266 | |
| 1267 | rv = callback.WaitForResult(); |
[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 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1270 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1271 | ASSERT_TRUE(response); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1272 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1273 | EXPECT_TRUE(response->headers); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1274 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1275 | |
| 1276 | std::string response_data; |
| 1277 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1278 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1279 | EXPECT_EQ("hello world", response_data); |
| 1280 | } |
| 1281 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1282 | TEST_P(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1283 | HttpRequestInfo request; |
| 1284 | request.method = "POST"; |
| 1285 | request.url = GURL("http://www.foo.com/"); |
| 1286 | request.load_flags = 0; |
| 1287 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1288 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1289 | std::unique_ptr<HttpTransaction> trans( |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1290 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1291 | |
| 1292 | MockRead data_reads[] = { |
| 1293 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1294 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1295 | }; |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1296 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1297 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1298 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1299 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1300 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1301 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1302 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1303 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1304 | rv = callback.WaitForResult(); |
| 1305 | EXPECT_EQ(OK, rv); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1306 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1307 | std::string response_data; |
| 1308 | rv = ReadTransaction(trans.get(), &response_data); |
| 1309 | EXPECT_EQ(OK, rv); |
| 1310 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1311 | } |
| 1312 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1313 | TEST_P(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1314 | HttpRequestInfo request; |
| 1315 | request.method = "POST"; |
| 1316 | request.url = GURL("http://www.foo.com/"); |
| 1317 | request.load_flags = 0; |
| 1318 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1319 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1320 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1321 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1322 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1323 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1324 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1325 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1326 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1327 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1328 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1329 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1330 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1331 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1332 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1333 | |
| 1334 | rv = callback.WaitForResult(); |
| 1335 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
| 1336 | } |
| 1337 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1338 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1339 | const MockWrite* write_failure, |
| 1340 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1341 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1342 | request.method = "GET"; |
| 1343 | request.url = GURL("http://www.foo.com/"); |
| 1344 | request.load_flags = 0; |
| 1345 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1346 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1347 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1348 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1349 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1350 | // Written data for successfully sending both requests. |
| 1351 | MockWrite data1_writes[] = { |
| 1352 | MockWrite("GET / HTTP/1.1\r\n" |
| 1353 | "Host: www.foo.com\r\n" |
| 1354 | "Connection: keep-alive\r\n\r\n"), |
| 1355 | MockWrite("GET / HTTP/1.1\r\n" |
| 1356 | "Host: www.foo.com\r\n" |
| 1357 | "Connection: keep-alive\r\n\r\n") |
| 1358 | }; |
| 1359 | |
| 1360 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1361 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1362 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1363 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1364 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1365 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1366 | |
| 1367 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1368 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1369 | data1_writes[1] = *write_failure; |
| 1370 | } else { |
| 1371 | ASSERT_TRUE(read_failure); |
| 1372 | data1_reads[2] = *read_failure; |
| 1373 | } |
| 1374 | |
| 1375 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1376 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1377 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1378 | |
| 1379 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1380 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1381 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1382 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1383 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1384 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1385 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1386 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1387 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1388 | "hello", "world" |
| 1389 | }; |
| 1390 | |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 1391 | uint32_t first_socket_log_id = NetLog::Source::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1392 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1393 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1394 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1395 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1396 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1397 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1398 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1399 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1400 | |
| 1401 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1402 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1403 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1404 | LoadTimingInfo load_timing_info; |
| 1405 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1406 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1407 | if (i == 0) { |
| 1408 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1409 | } else { |
| 1410 | // The second request should be using a new socket. |
| 1411 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1412 | } |
| 1413 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1414 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1415 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1416 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1417 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1418 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1419 | |
| 1420 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1421 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1422 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1423 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1424 | } |
| 1425 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1426 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1427 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1428 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1429 | const MockRead* read_failure, |
| 1430 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1431 | HttpRequestInfo request; |
| 1432 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1433 | request.url = GURL("https://www.foo.com/"); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1434 | request.load_flags = 0; |
| 1435 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1436 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1437 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1438 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1439 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1440 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1441 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1442 | if (use_spdy) { |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 1443 | ssl1.SetNextProto(GetProtocol()); |
| 1444 | ssl2.SetNextProto(GetProtocol()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1445 | } |
| 1446 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1447 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1448 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1449 | // SPDY versions of the request and response. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1450 | std::unique_ptr<SpdySerializedFrame> spdy_request(spdy_util_.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1451 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1452 | std::unique_ptr<SpdySerializedFrame> spdy_response( |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1453 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1454 | std::unique_ptr<SpdySerializedFrame> spdy_data( |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1455 | spdy_util_.ConstructSpdyBodyFrame(1, "hello", 5, true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1456 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1457 | // HTTP/1.1 versions of the request and response. |
| 1458 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1459 | "Host: www.foo.com\r\n" |
| 1460 | "Connection: keep-alive\r\n\r\n"; |
| 1461 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1462 | const char kHttpData[] = "hello"; |
| 1463 | |
| 1464 | std::vector<MockRead> data1_reads; |
| 1465 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1466 | if (write_failure) { |
| 1467 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1468 | data1_writes.push_back(*write_failure); |
| 1469 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1470 | } else { |
| 1471 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1472 | if (use_spdy) { |
| 1473 | data1_writes.push_back(CreateMockWrite(*spdy_request)); |
| 1474 | } else { |
| 1475 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1476 | } |
| 1477 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1478 | } |
| 1479 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1480 | StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(), |
| 1481 | &data1_writes[0], data1_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1482 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1483 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1484 | std::vector<MockRead> data2_reads; |
| 1485 | std::vector<MockWrite> data2_writes; |
| 1486 | |
| 1487 | if (use_spdy) { |
| 1488 | data2_writes.push_back(CreateMockWrite(*spdy_request, 0, ASYNC)); |
| 1489 | |
| 1490 | data2_reads.push_back(CreateMockRead(*spdy_response, 1, ASYNC)); |
| 1491 | data2_reads.push_back(CreateMockRead(*spdy_data, 2, ASYNC)); |
| 1492 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1493 | } else { |
| 1494 | data2_writes.push_back( |
| 1495 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1496 | |
| 1497 | data2_reads.push_back( |
| 1498 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1499 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1500 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1501 | } |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 1502 | SequencedSocketData data2(&data2_reads[0], data2_reads.size(), |
| 1503 | &data2_writes[0], data2_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1504 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1505 | |
| 1506 | // Preconnect a socket. |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 1507 | session->http_stream_factory()->PreconnectStreams(1, request); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1508 | // Wait for the preconnect to complete. |
| 1509 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1510 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1511 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1512 | |
| 1513 | // Make the request. |
| 1514 | TestCompletionCallback callback; |
| 1515 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1516 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1517 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1518 | |
| 1519 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1520 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1521 | |
| 1522 | rv = callback.WaitForResult(); |
| 1523 | EXPECT_EQ(OK, rv); |
| 1524 | |
| 1525 | LoadTimingInfo load_timing_info; |
| 1526 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1527 | TestLoadTimingNotReused( |
| 1528 | load_timing_info, |
| 1529 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1530 | |
| 1531 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1532 | ASSERT_TRUE(response); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1533 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1534 | EXPECT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1535 | if (response->was_fetched_via_spdy) { |
| 1536 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1537 | } else { |
| 1538 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1539 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1540 | |
| 1541 | std::string response_data; |
| 1542 | rv = ReadTransaction(trans.get(), &response_data); |
| 1543 | EXPECT_EQ(OK, rv); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1544 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1545 | } |
| 1546 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1547 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 1548 | KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1549 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1550 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1551 | } |
| 1552 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1553 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1554 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[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] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1558 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1559 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1560 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1561 | } |
| 1562 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1563 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1564 | // if the socket was a reused keep alive socket. |
| 1565 | TEST_P(HttpNetworkTransactionTest, KeepAlive408) { |
| 1566 | MockRead read_failure(SYNCHRONOUS, |
| 1567 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1568 | "Connection: Keep-Alive\r\n" |
| 1569 | "Content-Length: 6\r\n\r\n" |
| 1570 | "Pickle"); |
| 1571 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1572 | } |
| 1573 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1574 | TEST_P(HttpNetworkTransactionTest, |
| 1575 | PreconnectErrorNotConnectedOnWrite) { |
| 1576 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1577 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1578 | } |
| 1579 | |
| 1580 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorReset) { |
| 1581 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1582 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1583 | } |
| 1584 | |
| 1585 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
| 1586 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1587 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1588 | } |
| 1589 | |
| 1590 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
| 1591 | MockRead read_failure(ASYNC, OK); // EOF |
| 1592 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1593 | } |
| 1594 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1595 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1596 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
| 1597 | TEST_P(HttpNetworkTransactionTest, RetryOnIdle408) { |
| 1598 | MockRead read_failure(SYNCHRONOUS, |
| 1599 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1600 | "Connection: Keep-Alive\r\n" |
| 1601 | "Content-Length: 6\r\n\r\n" |
| 1602 | "Pickle"); |
| 1603 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1604 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1605 | } |
| 1606 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1607 | TEST_P(HttpNetworkTransactionTest, |
| 1608 | SpdyPreconnectErrorNotConnectedOnWrite) { |
| 1609 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1610 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1611 | } |
| 1612 | |
| 1613 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
| 1614 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1615 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1616 | } |
| 1617 | |
| 1618 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
| 1619 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1620 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1621 | } |
| 1622 | |
| 1623 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
| 1624 | MockRead read_failure(ASYNC, OK); // EOF |
| 1625 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1626 | } |
| 1627 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1628 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1629 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1630 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1631 | request.url = GURL("http://www.example.org/"); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1632 | request.load_flags = 0; |
| 1633 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1634 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1635 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1636 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1637 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1638 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1639 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1640 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1641 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1642 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1643 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1644 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1645 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1646 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1647 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1648 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1649 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1650 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1651 | |
| 1652 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1653 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1654 | |
| 1655 | IPEndPoint endpoint; |
| 1656 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 1657 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1658 | } |
| 1659 | |
| 1660 | // What do various browsers do when the server closes a non-keepalive |
| 1661 | // connection without sending any response header or body? |
| 1662 | // |
| 1663 | // IE7: error page |
| 1664 | // Safari 3.1.2 (Windows): error page |
| 1665 | // Firefox 3.0.1: blank page |
| 1666 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1667 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1668 | // Us: error page (EMPTY_RESPONSE) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1669 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1670 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1671 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1672 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1673 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1674 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1675 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1676 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1677 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1678 | EXPECT_EQ(ERR_EMPTY_RESPONSE, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1679 | } |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1680 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1681 | // Test that network access can be deferred and resumed. |
| 1682 | TEST_P(HttpNetworkTransactionTest, ThrottleBeforeNetworkStart) { |
| 1683 | HttpRequestInfo request; |
| 1684 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1685 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1686 | request.load_flags = 0; |
| 1687 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1688 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1689 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1690 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1691 | |
| 1692 | // Defer on OnBeforeNetworkStart. |
| 1693 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1694 | trans->SetBeforeNetworkStartCallback( |
| 1695 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1696 | base::Unretained(&net_start_handler))); |
| 1697 | |
| 1698 | MockRead data_reads[] = { |
| 1699 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1700 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1701 | MockRead("hello"), |
| 1702 | MockRead(SYNCHRONOUS, 0), |
| 1703 | }; |
| 1704 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1705 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1706 | |
| 1707 | TestCompletionCallback callback; |
| 1708 | |
| 1709 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1710 | EXPECT_EQ(ERR_IO_PENDING, rv); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1711 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1712 | |
| 1713 | // Should have deferred for network start. |
| 1714 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1715 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1716 | |
| 1717 | trans->ResumeNetworkStart(); |
| 1718 | rv = callback.WaitForResult(); |
| 1719 | EXPECT_EQ(OK, rv); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1720 | EXPECT_TRUE(trans->GetResponseInfo()); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1721 | |
| 1722 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
| 1723 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
| 1724 | if (rv == ERR_IO_PENDING) |
| 1725 | rv = callback.WaitForResult(); |
| 1726 | EXPECT_EQ(5, rv); |
| 1727 | trans.reset(); |
| 1728 | } |
| 1729 | |
| 1730 | // Test that network use can be deferred and canceled. |
| 1731 | TEST_P(HttpNetworkTransactionTest, ThrottleAndCancelBeforeNetworkStart) { |
| 1732 | HttpRequestInfo request; |
| 1733 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1734 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1735 | request.load_flags = 0; |
| 1736 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1737 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1738 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1739 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1740 | |
| 1741 | // Defer on OnBeforeNetworkStart. |
| 1742 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1743 | trans->SetBeforeNetworkStartCallback( |
| 1744 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1745 | base::Unretained(&net_start_handler))); |
| 1746 | |
| 1747 | TestCompletionCallback callback; |
| 1748 | |
| 1749 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1750 | EXPECT_EQ(ERR_IO_PENDING, rv); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1751 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1752 | |
| 1753 | // Should have deferred for network start. |
| 1754 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1755 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1756 | } |
| 1757 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1758 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1759 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1760 | // destructor in such situations. |
| 1761 | // See http://crbug.com/154712 and http://crbug.com/156609. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1762 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1763 | HttpRequestInfo request; |
| 1764 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1765 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1766 | request.load_flags = 0; |
| 1767 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1768 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1769 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1770 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1771 | |
| 1772 | MockRead data_reads[] = { |
| 1773 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1774 | MockRead("Connection: keep-alive\r\n"), |
| 1775 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1776 | MockRead("hello"), |
| 1777 | MockRead(SYNCHRONOUS, 0), |
| 1778 | }; |
| 1779 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1780 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1781 | |
| 1782 | TestCompletionCallback callback; |
| 1783 | |
| 1784 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1785 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1786 | |
| 1787 | rv = callback.WaitForResult(); |
| 1788 | EXPECT_EQ(OK, rv); |
| 1789 | |
| 1790 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1791 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1792 | if (rv == ERR_IO_PENDING) |
| 1793 | rv = callback.WaitForResult(); |
| 1794 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1795 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1796 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1797 | |
| 1798 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1799 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1800 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1801 | } |
| 1802 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1803 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1804 | HttpRequestInfo request; |
| 1805 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1806 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1807 | request.load_flags = 0; |
| 1808 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1809 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1810 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1811 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1812 | |
| 1813 | MockRead data_reads[] = { |
| 1814 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1815 | MockRead("Connection: keep-alive\r\n"), |
| 1816 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1817 | MockRead(SYNCHRONOUS, 0), |
| 1818 | }; |
| 1819 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1820 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1821 | |
| 1822 | TestCompletionCallback callback; |
| 1823 | |
| 1824 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1825 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1826 | |
| 1827 | rv = callback.WaitForResult(); |
| 1828 | EXPECT_EQ(OK, rv); |
| 1829 | |
| 1830 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1831 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1832 | if (rv == ERR_IO_PENDING) |
| 1833 | rv = callback.WaitForResult(); |
| 1834 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1835 | |
| 1836 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1837 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1838 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1839 | } |
| 1840 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1841 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1842 | // reading the body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1843 | TEST_P(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1844 | HttpRequestInfo request; |
| 1845 | request.method = "GET"; |
| 1846 | request.url = GURL("http://www.foo.com/"); |
| 1847 | request.load_flags = 0; |
| 1848 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1849 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1850 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1851 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1852 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1853 | const char* request_data = |
| 1854 | "GET / HTTP/1.1\r\n" |
| 1855 | "Host: www.foo.com\r\n" |
| 1856 | "Connection: keep-alive\r\n\r\n"; |
| 1857 | MockWrite data_writes[] = { |
| 1858 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 1859 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 1860 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 1861 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 1862 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 1863 | }; |
| 1864 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1865 | // Note that because all these reads happen in the same |
| 1866 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 1867 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1868 | MockRead data_reads[] = { |
| 1869 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 1870 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 1871 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 1872 | MockRead(ASYNC, 7, |
| 1873 | "HTTP/1.1 302 Found\r\n" |
| 1874 | "Content-Length: 0\r\n\r\n"), |
| 1875 | MockRead(ASYNC, 9, |
| 1876 | "HTTP/1.1 302 Found\r\n" |
| 1877 | "Content-Length: 5\r\n\r\n" |
| 1878 | "hello"), |
| 1879 | MockRead(ASYNC, 11, |
| 1880 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 1881 | "Content-Length: 0\r\n\r\n"), |
| 1882 | MockRead(ASYNC, 13, |
| 1883 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 1884 | "Content-Length: 5\r\n\r\n" |
| 1885 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1886 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1887 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 1888 | // the set_busy_before_sync_reads(true) call, while the |
| 1889 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 1890 | // reuseable. See http://crbug.com/544255. |
| 1891 | MockRead(ASYNC, 15, |
| 1892 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 1893 | "Content-Length: 5\r\n\r\n"), |
| 1894 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1895 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1896 | MockRead(ASYNC, 18, |
| 1897 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 1898 | "Content-Length: 5\r\n\r\n" |
| 1899 | "he"), |
| 1900 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 1901 | |
| 1902 | // The body of the final request is actually read. |
| 1903 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1904 | MockRead(ASYNC, 22, "hello"), |
| 1905 | }; |
| 1906 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 1907 | arraysize(data_writes)); |
| 1908 | data.set_busy_before_sync_reads(true); |
| 1909 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1910 | |
| 1911 | const int kNumUnreadBodies = arraysize(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1912 | std::string response_lines[kNumUnreadBodies]; |
| 1913 | |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 1914 | uint32_t first_socket_log_id = NetLog::Source::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1915 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1916 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1917 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1918 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1919 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1920 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1921 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1922 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1923 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1924 | LoadTimingInfo load_timing_info; |
| 1925 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1926 | if (i == 0) { |
| 1927 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1928 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1929 | } else { |
| 1930 | TestLoadTimingReused(load_timing_info); |
| 1931 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 1932 | } |
| 1933 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1934 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1935 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1936 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1937 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1938 | response_lines[i] = response->headers->GetStatusLine(); |
| 1939 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1940 | // Delete the transaction without reading the response bodies. Then spin |
| 1941 | // the message loop, so the response bodies are drained. |
| 1942 | trans.reset(); |
| 1943 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1944 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1945 | |
| 1946 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1947 | "HTTP/1.1 204 No Content", |
| 1948 | "HTTP/1.1 205 Reset Content", |
| 1949 | "HTTP/1.1 304 Not Modified", |
| 1950 | "HTTP/1.1 302 Found", |
| 1951 | "HTTP/1.1 302 Found", |
| 1952 | "HTTP/1.1 301 Moved Permanently", |
| 1953 | "HTTP/1.1 301 Moved Permanently", |
| 1954 | "HTTP/1.1 200 Hunky-Dory", |
| 1955 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1956 | }; |
| 1957 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 1958 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 1959 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1960 | |
| 1961 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 1962 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 1963 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1964 | TestCompletionCallback callback; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1965 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1966 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1967 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1968 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1969 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1970 | ASSERT_TRUE(response); |
| 1971 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1972 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1973 | std::string response_data; |
| 1974 | rv = ReadTransaction(trans.get(), &response_data); |
| 1975 | EXPECT_EQ(OK, rv); |
| 1976 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1977 | } |
| 1978 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 1979 | // Sockets that receive extra data after a response is complete should not be |
| 1980 | // reused. |
| 1981 | TEST_P(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
| 1982 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1983 | MockWrite data_writes1[] = { |
| 1984 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1985 | "Host: www.borked.com\r\n" |
| 1986 | "Connection: keep-alive\r\n\r\n"), |
| 1987 | }; |
| 1988 | |
| 1989 | MockRead data_reads1[] = { |
| 1990 | MockRead("HTTP/1.1 200 OK\r\n" |
| 1991 | "Connection: keep-alive\r\n" |
| 1992 | "Content-Length: 22\r\n\r\n" |
| 1993 | "This server is borked."), |
| 1994 | }; |
| 1995 | |
| 1996 | MockWrite data_writes2[] = { |
| 1997 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 1998 | "Host: www.borked.com\r\n" |
| 1999 | "Connection: keep-alive\r\n\r\n"), |
| 2000 | }; |
| 2001 | |
| 2002 | MockRead data_reads2[] = { |
| 2003 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2004 | "Content-Length: 3\r\n\r\n" |
| 2005 | "foo"), |
| 2006 | }; |
| 2007 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2008 | data_writes1, arraysize(data_writes1)); |
| 2009 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2010 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2011 | data_writes2, arraysize(data_writes2)); |
| 2012 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2013 | |
| 2014 | TestCompletionCallback callback; |
| 2015 | HttpRequestInfo request1; |
| 2016 | request1.method = "HEAD"; |
| 2017 | request1.url = GURL("http://www.borked.com/"); |
| 2018 | |
| 2019 | std::unique_ptr<HttpTransaction> trans1( |
| 2020 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2021 | int rv = trans1->Start(&request1, callback.callback(), BoundNetLog()); |
| 2022 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 2023 | |
| 2024 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2025 | ASSERT_TRUE(response1); |
| 2026 | ASSERT_TRUE(response1->headers); |
| 2027 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2028 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2029 | |
| 2030 | std::string response_data1; |
| 2031 | EXPECT_EQ(OK, ReadTransaction(trans1.get(), &response_data1)); |
| 2032 | EXPECT_EQ("", response_data1); |
| 2033 | // Deleting the transaction attempts to release the socket back into the |
| 2034 | // socket pool. |
| 2035 | trans1.reset(); |
| 2036 | |
| 2037 | HttpRequestInfo request2; |
| 2038 | request2.method = "GET"; |
| 2039 | request2.url = GURL("http://www.borked.com/foo"); |
| 2040 | |
| 2041 | std::unique_ptr<HttpTransaction> trans2( |
| 2042 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2043 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 2044 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 2045 | |
| 2046 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2047 | ASSERT_TRUE(response2); |
| 2048 | ASSERT_TRUE(response2->headers); |
| 2049 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2050 | |
| 2051 | std::string response_data2; |
| 2052 | EXPECT_EQ(OK, ReadTransaction(trans2.get(), &response_data2)); |
| 2053 | EXPECT_EQ("foo", response_data2); |
| 2054 | } |
| 2055 | |
| 2056 | TEST_P(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
| 2057 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2058 | MockWrite data_writes1[] = { |
| 2059 | MockWrite("GET / HTTP/1.1\r\n" |
| 2060 | "Host: www.borked.com\r\n" |
| 2061 | "Connection: keep-alive\r\n\r\n"), |
| 2062 | }; |
| 2063 | |
| 2064 | MockRead data_reads1[] = { |
| 2065 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2066 | "Connection: keep-alive\r\n" |
| 2067 | "Content-Length: 22\r\n\r\n" |
| 2068 | "This server is borked." |
| 2069 | "Bonus data!"), |
| 2070 | }; |
| 2071 | |
| 2072 | MockWrite data_writes2[] = { |
| 2073 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2074 | "Host: www.borked.com\r\n" |
| 2075 | "Connection: keep-alive\r\n\r\n"), |
| 2076 | }; |
| 2077 | |
| 2078 | MockRead data_reads2[] = { |
| 2079 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2080 | "Content-Length: 3\r\n\r\n" |
| 2081 | "foo"), |
| 2082 | }; |
| 2083 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2084 | data_writes1, arraysize(data_writes1)); |
| 2085 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2086 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2087 | data_writes2, arraysize(data_writes2)); |
| 2088 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2089 | |
| 2090 | TestCompletionCallback callback; |
| 2091 | HttpRequestInfo request1; |
| 2092 | request1.method = "GET"; |
| 2093 | request1.url = GURL("http://www.borked.com/"); |
| 2094 | |
| 2095 | std::unique_ptr<HttpTransaction> trans1( |
| 2096 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2097 | int rv = trans1->Start(&request1, callback.callback(), BoundNetLog()); |
| 2098 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 2099 | |
| 2100 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2101 | ASSERT_TRUE(response1); |
| 2102 | ASSERT_TRUE(response1->headers); |
| 2103 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2104 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2105 | |
| 2106 | std::string response_data1; |
| 2107 | EXPECT_EQ(OK, ReadTransaction(trans1.get(), &response_data1)); |
| 2108 | EXPECT_EQ("This server is borked.", response_data1); |
| 2109 | // Deleting the transaction attempts to release the socket back into the |
| 2110 | // socket pool. |
| 2111 | trans1.reset(); |
| 2112 | |
| 2113 | HttpRequestInfo request2; |
| 2114 | request2.method = "GET"; |
| 2115 | request2.url = GURL("http://www.borked.com/foo"); |
| 2116 | |
| 2117 | std::unique_ptr<HttpTransaction> trans2( |
| 2118 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2119 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 2120 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 2121 | |
| 2122 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2123 | ASSERT_TRUE(response2); |
| 2124 | ASSERT_TRUE(response2->headers); |
| 2125 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2126 | |
| 2127 | std::string response_data2; |
| 2128 | EXPECT_EQ(OK, ReadTransaction(trans2.get(), &response_data2)); |
| 2129 | EXPECT_EQ("foo", response_data2); |
| 2130 | } |
| 2131 | |
| 2132 | TEST_P(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
| 2133 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2134 | MockWrite data_writes1[] = { |
| 2135 | MockWrite("GET / HTTP/1.1\r\n" |
| 2136 | "Host: www.borked.com\r\n" |
| 2137 | "Connection: keep-alive\r\n\r\n"), |
| 2138 | }; |
| 2139 | |
| 2140 | MockRead data_reads1[] = { |
| 2141 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2142 | "Connection: keep-alive\r\n" |
| 2143 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2144 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2145 | MockRead("0\r\n\r\nBonus data!"), |
| 2146 | }; |
| 2147 | |
| 2148 | MockWrite data_writes2[] = { |
| 2149 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2150 | "Host: www.borked.com\r\n" |
| 2151 | "Connection: keep-alive\r\n\r\n"), |
| 2152 | }; |
| 2153 | |
| 2154 | MockRead data_reads2[] = { |
| 2155 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2156 | "Content-Length: 3\r\n\r\n" |
| 2157 | "foo"), |
| 2158 | }; |
| 2159 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2160 | data_writes1, arraysize(data_writes1)); |
| 2161 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2162 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2163 | data_writes2, arraysize(data_writes2)); |
| 2164 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2165 | |
| 2166 | TestCompletionCallback callback; |
| 2167 | HttpRequestInfo request1; |
| 2168 | request1.method = "GET"; |
| 2169 | request1.url = GURL("http://www.borked.com/"); |
| 2170 | |
| 2171 | std::unique_ptr<HttpTransaction> trans1( |
| 2172 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2173 | int rv = trans1->Start(&request1, callback.callback(), BoundNetLog()); |
| 2174 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 2175 | |
| 2176 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2177 | ASSERT_TRUE(response1); |
| 2178 | ASSERT_TRUE(response1->headers); |
| 2179 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2180 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2181 | |
| 2182 | std::string response_data1; |
| 2183 | EXPECT_EQ(OK, ReadTransaction(trans1.get(), &response_data1)); |
| 2184 | EXPECT_EQ("This server is borked.", response_data1); |
| 2185 | // Deleting the transaction attempts to release the socket back into the |
| 2186 | // socket pool. |
| 2187 | trans1.reset(); |
| 2188 | |
| 2189 | HttpRequestInfo request2; |
| 2190 | request2.method = "GET"; |
| 2191 | request2.url = GURL("http://www.borked.com/foo"); |
| 2192 | |
| 2193 | std::unique_ptr<HttpTransaction> trans2( |
| 2194 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2195 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 2196 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 2197 | |
| 2198 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2199 | ASSERT_TRUE(response2); |
| 2200 | ASSERT_TRUE(response2->headers); |
| 2201 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2202 | |
| 2203 | std::string response_data2; |
| 2204 | EXPECT_EQ(OK, ReadTransaction(trans2.get(), &response_data2)); |
| 2205 | EXPECT_EQ("foo", response_data2); |
| 2206 | } |
| 2207 | |
| 2208 | // This is a little different from the others - it tests the case that the |
| 2209 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2210 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2211 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
| 2212 | TEST_P(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
| 2213 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2214 | MockWrite data_writes1[] = { |
| 2215 | MockWrite("GET / HTTP/1.1\r\n" |
| 2216 | "Host: www.borked.com\r\n" |
| 2217 | "Connection: keep-alive\r\n\r\n"), |
| 2218 | }; |
| 2219 | |
| 2220 | MockRead data_reads1[] = { |
| 2221 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2222 | "Connection: keep-alive\r\n" |
| 2223 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2224 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2225 | MockRead("0\r\n\r\nBonus data!"), |
| 2226 | }; |
| 2227 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2228 | data_writes1, arraysize(data_writes1)); |
| 2229 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2230 | |
| 2231 | TestCompletionCallback callback; |
| 2232 | HttpRequestInfo request1; |
| 2233 | request1.method = "GET"; |
| 2234 | request1.url = GURL("http://www.borked.com/"); |
| 2235 | |
| 2236 | std::unique_ptr<HttpTransaction> trans1( |
| 2237 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2238 | int rv = trans1->Start(&request1, callback.callback(), BoundNetLog()); |
| 2239 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 2240 | |
| 2241 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2242 | ASSERT_TRUE(response1); |
| 2243 | ASSERT_TRUE(response1->headers); |
| 2244 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2245 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2246 | |
| 2247 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2248 | // response body. |
| 2249 | trans1.reset(); |
| 2250 | |
| 2251 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2252 | // socket can't be reused, rather than returning it to the socket pool. |
| 2253 | base::RunLoop().RunUntilIdle(); |
| 2254 | |
| 2255 | // There should be no idle sockets in the pool. |
| 2256 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2257 | } |
| 2258 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2259 | // Test the request-challenge-retry sequence for basic auth. |
| 2260 | // (basic auth is the easiest to mock, because it has no randomness). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2261 | TEST_P(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2262 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2263 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2264 | request.url = GURL("http://www.example.org/"); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2265 | request.load_flags = 0; |
| 2266 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2267 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2268 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2269 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2270 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 2271 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2272 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2273 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2274 | MockWrite( |
| 2275 | "GET / HTTP/1.1\r\n" |
| 2276 | "Host: www.example.org\r\n" |
| 2277 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2278 | }; |
| 2279 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2280 | MockRead data_reads1[] = { |
| 2281 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2282 | // Give a couple authenticate options (only the middle one is actually |
| 2283 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2284 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2285 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2286 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2287 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2288 | // Large content-length -- won't matter, as connection will be reset. |
| 2289 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2290 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2291 | }; |
| 2292 | |
| 2293 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2294 | // be issuing -- the final header line contains the credentials. |
| 2295 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2296 | MockWrite( |
| 2297 | "GET / HTTP/1.1\r\n" |
| 2298 | "Host: www.example.org\r\n" |
| 2299 | "Connection: keep-alive\r\n" |
| 2300 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2301 | }; |
| 2302 | |
| 2303 | // Lastly, the server responds with the actual content. |
| 2304 | MockRead data_reads2[] = { |
| 2305 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2306 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2307 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2308 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2309 | }; |
| 2310 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2311 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2312 | data_writes1, arraysize(data_writes1)); |
| 2313 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2314 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2315 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2316 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2317 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2318 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2319 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2320 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2321 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2322 | |
| 2323 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2324 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2325 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2326 | LoadTimingInfo load_timing_info1; |
| 2327 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2328 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2329 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2330 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
| 2331 | EXPECT_EQ(writes_size1, trans->GetTotalSentBytes()); |
| 2332 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2333 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
| 2334 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2335 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2336 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2337 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2338 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2339 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2340 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2341 | rv = trans->RestartWithAuth( |
| 2342 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2343 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2344 | |
| 2345 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2346 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2347 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2348 | LoadTimingInfo load_timing_info2; |
| 2349 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2350 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2351 | // The load timing after restart should have a new socket ID, and times after |
| 2352 | // those of the first load timing. |
| 2353 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2354 | load_timing_info2.connect_timing.connect_start); |
| 2355 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2356 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2357 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
| 2358 | EXPECT_EQ(writes_size1 + writes_size2, trans->GetTotalSentBytes()); |
| 2359 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2360 | EXPECT_EQ(reads_size1 + reads_size2, trans->GetTotalReceivedBytes()); |
| 2361 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2362 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2363 | ASSERT_TRUE(response); |
| 2364 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2365 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2366 | } |
| 2367 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2368 | // Test the request-challenge-retry sequence for basic auth. |
| 2369 | // (basic auth is the easiest to mock, because it has no randomness). |
| 2370 | TEST_P(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
| 2371 | HttpRequestInfo request; |
| 2372 | request.method = "GET"; |
| 2373 | request.url = GURL("http://www.example.org/"); |
| 2374 | request.load_flags = 0; |
| 2375 | |
| 2376 | TestNetLog log; |
| 2377 | MockHostResolver* resolver = new MockHostResolver(); |
| 2378 | session_deps_.net_log = &log; |
| 2379 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2380 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 2381 | std::unique_ptr<HttpTransaction> trans( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2382 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2383 | |
| 2384 | resolver->rules()->ClearRules(); |
| 2385 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2386 | |
| 2387 | MockWrite data_writes1[] = { |
| 2388 | MockWrite("GET / HTTP/1.1\r\n" |
| 2389 | "Host: www.example.org\r\n" |
| 2390 | "Connection: keep-alive\r\n\r\n"), |
| 2391 | }; |
| 2392 | |
| 2393 | MockRead data_reads1[] = { |
| 2394 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2395 | // Give a couple authenticate options (only the middle one is actually |
| 2396 | // supported). |
| 2397 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2398 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2399 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2400 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2401 | // Large content-length -- won't matter, as connection will be reset. |
| 2402 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2403 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2404 | }; |
| 2405 | |
| 2406 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2407 | // be issuing -- the final header line contains the credentials. |
| 2408 | MockWrite data_writes2[] = { |
| 2409 | MockWrite("GET / HTTP/1.1\r\n" |
| 2410 | "Host: www.example.org\r\n" |
| 2411 | "Connection: keep-alive\r\n" |
| 2412 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2413 | }; |
| 2414 | |
| 2415 | // Lastly, the server responds with the actual content. |
| 2416 | MockRead data_reads2[] = { |
| 2417 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2418 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2419 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2420 | }; |
| 2421 | |
| 2422 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2423 | data_writes1, arraysize(data_writes1)); |
| 2424 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2425 | data_writes2, arraysize(data_writes2)); |
| 2426 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2427 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2428 | |
| 2429 | TestCompletionCallback callback1; |
| 2430 | |
| 2431 | EXPECT_EQ(OK, callback1.GetResult(trans->Start(&request, callback1.callback(), |
| 2432 | BoundNetLog()))); |
| 2433 | |
| 2434 | LoadTimingInfo load_timing_info1; |
| 2435 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2436 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2437 | |
| 2438 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
| 2439 | EXPECT_EQ(writes_size1, trans->GetTotalSentBytes()); |
| 2440 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
| 2441 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
| 2442 | |
| 2443 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2444 | ASSERT_TRUE(response); |
| 2445 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2446 | |
| 2447 | IPEndPoint endpoint; |
| 2448 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 2449 | ASSERT_FALSE(endpoint.address().empty()); |
| 2450 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2451 | |
| 2452 | resolver->rules()->ClearRules(); |
| 2453 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2454 | |
| 2455 | TestCompletionCallback callback2; |
| 2456 | |
| 2457 | EXPECT_EQ(OK, callback2.GetResult(trans->RestartWithAuth( |
| 2458 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2459 | |
| 2460 | LoadTimingInfo load_timing_info2; |
| 2461 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2462 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2463 | // The load timing after restart should have a new socket ID, and times after |
| 2464 | // those of the first load timing. |
| 2465 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2466 | load_timing_info2.connect_timing.connect_start); |
| 2467 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2468 | |
| 2469 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
| 2470 | EXPECT_EQ(writes_size1 + writes_size2, trans->GetTotalSentBytes()); |
| 2471 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
| 2472 | EXPECT_EQ(reads_size1 + reads_size2, trans->GetTotalReceivedBytes()); |
| 2473 | |
| 2474 | response = trans->GetResponseInfo(); |
| 2475 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2476 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2477 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2478 | |
| 2479 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 2480 | ASSERT_FALSE(endpoint.address().empty()); |
| 2481 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2482 | } |
| 2483 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2484 | TEST_P(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2485 | HttpRequestInfo request; |
| 2486 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2487 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2488 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2489 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2490 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2491 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 2492 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2493 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2494 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2495 | MockWrite( |
| 2496 | "GET / HTTP/1.1\r\n" |
| 2497 | "Host: www.example.org\r\n" |
| 2498 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2499 | }; |
| 2500 | |
| 2501 | MockRead data_reads[] = { |
| 2502 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2503 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2504 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2505 | // Large content-length -- won't matter, as connection will be reset. |
| 2506 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2507 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2508 | }; |
| 2509 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2510 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2511 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2512 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2513 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2514 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2515 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2516 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2517 | |
| 2518 | rv = callback.WaitForResult(); |
| 2519 | EXPECT_EQ(0, rv); |
| 2520 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2521 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
| 2522 | EXPECT_EQ(writes_size, trans->GetTotalSentBytes()); |
| 2523 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2524 | EXPECT_EQ(reads_size, trans->GetTotalReceivedBytes()); |
| 2525 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2526 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2527 | ASSERT_TRUE(response); |
| 2528 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2529 | } |
| 2530 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2531 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2532 | // connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2533 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2534 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2535 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2536 | // reused. See http://crbug.com/544255. |
| 2537 | for (int i = 0; i < 2; ++i) { |
| 2538 | HttpRequestInfo request; |
| 2539 | request.method = "GET"; |
| 2540 | request.url = GURL("http://www.example.org/"); |
| 2541 | request.load_flags = 0; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2542 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2543 | TestNetLog log; |
| 2544 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2545 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2546 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2547 | MockWrite data_writes[] = { |
| 2548 | MockWrite(ASYNC, 0, |
| 2549 | "GET / HTTP/1.1\r\n" |
| 2550 | "Host: www.example.org\r\n" |
| 2551 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2552 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2553 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2554 | // be issuing -- the final header line contains the credentials. |
| 2555 | MockWrite(ASYNC, 6, |
| 2556 | "GET / HTTP/1.1\r\n" |
| 2557 | "Host: www.example.org\r\n" |
| 2558 | "Connection: keep-alive\r\n" |
| 2559 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2560 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2561 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2562 | MockRead data_reads[] = { |
| 2563 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2564 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2565 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2566 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2567 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2568 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2569 | // Lastly, the server responds with the actual content. |
| 2570 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2571 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2572 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2573 | MockRead(ASYNC, 10, "Hello"), |
| 2574 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2575 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2576 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 2577 | arraysize(data_writes)); |
| 2578 | data.set_busy_before_sync_reads(true); |
| 2579 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2580 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2581 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2582 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2583 | std::unique_ptr<HttpTransaction> trans( |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2584 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2585 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 2586 | ASSERT_EQ(OK, callback1.GetResult(rv)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2587 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2588 | LoadTimingInfo load_timing_info1; |
| 2589 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2590 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2591 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2592 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2593 | ASSERT_TRUE(response); |
| 2594 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2595 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2596 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2597 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2598 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2599 | callback2.callback()); |
| 2600 | ASSERT_EQ(OK, callback2.GetResult(rv)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2601 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2602 | LoadTimingInfo load_timing_info2; |
| 2603 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2604 | TestLoadTimingReused(load_timing_info2); |
| 2605 | // The load timing after restart should have the same socket ID, and times |
| 2606 | // those of the first load timing. |
| 2607 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2608 | load_timing_info2.send_start); |
| 2609 | 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] | 2610 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2611 | response = trans->GetResponseInfo(); |
| 2612 | ASSERT_TRUE(response); |
| 2613 | EXPECT_FALSE(response->auth_challenge); |
| 2614 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2615 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2616 | std::string response_data; |
| 2617 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2618 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2619 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
| 2620 | EXPECT_EQ(writes_size, trans->GetTotalSentBytes()); |
| 2621 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 2622 | EXPECT_EQ(reads_size, trans->GetTotalReceivedBytes()); |
| 2623 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2624 | } |
| 2625 | |
| 2626 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2627 | // connection and with no response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2628 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2629 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2630 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2631 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2632 | request.load_flags = 0; |
| 2633 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2634 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2635 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2636 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2637 | MockWrite( |
| 2638 | "GET / HTTP/1.1\r\n" |
| 2639 | "Host: www.example.org\r\n" |
| 2640 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2641 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2642 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2643 | // be issuing -- the final header line contains the credentials. |
| 2644 | MockWrite( |
| 2645 | "GET / HTTP/1.1\r\n" |
| 2646 | "Host: www.example.org\r\n" |
| 2647 | "Connection: keep-alive\r\n" |
| 2648 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2649 | }; |
| 2650 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2651 | MockRead data_reads1[] = { |
| 2652 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2653 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2654 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2655 | |
| 2656 | // Lastly, the server responds with the actual content. |
| 2657 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2658 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2659 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2660 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2661 | }; |
| 2662 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2663 | // An incorrect reconnect would cause this to be read. |
| 2664 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2665 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2666 | }; |
| 2667 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2668 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2669 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2670 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2671 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2672 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2673 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2674 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2675 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2676 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2677 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2678 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2679 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2680 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2681 | |
| 2682 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2683 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2684 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2685 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2686 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2687 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2688 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2689 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2690 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2691 | rv = trans->RestartWithAuth( |
| 2692 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2693 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2694 | |
| 2695 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2696 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2697 | |
| 2698 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2699 | ASSERT_TRUE(response); |
| 2700 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2701 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2702 | } |
| 2703 | |
| 2704 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2705 | // connection and with a large response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2706 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2707 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2708 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2709 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2710 | request.load_flags = 0; |
| 2711 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2712 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2713 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2714 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2715 | MockWrite( |
| 2716 | "GET / HTTP/1.1\r\n" |
| 2717 | "Host: www.example.org\r\n" |
| 2718 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2719 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2720 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2721 | // be issuing -- the final header line contains the credentials. |
| 2722 | MockWrite( |
| 2723 | "GET / HTTP/1.1\r\n" |
| 2724 | "Host: www.example.org\r\n" |
| 2725 | "Connection: keep-alive\r\n" |
| 2726 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2727 | }; |
| 2728 | |
| 2729 | // Respond with 5 kb of response body. |
| 2730 | std::string large_body_string("Unauthorized"); |
| 2731 | large_body_string.append(5 * 1024, ' '); |
| 2732 | large_body_string.append("\r\n"); |
| 2733 | |
| 2734 | MockRead data_reads1[] = { |
| 2735 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2736 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2737 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2738 | // 5134 = 12 + 5 * 1024 + 2 |
| 2739 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2740 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2741 | |
| 2742 | // Lastly, the server responds with the actual content. |
| 2743 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2744 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2745 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2746 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2747 | }; |
| 2748 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2749 | // An incorrect reconnect would cause this to be read. |
| 2750 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2751 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2752 | }; |
| 2753 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2754 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2755 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2756 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2757 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2758 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2759 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2760 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2761 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2762 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2763 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2764 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2765 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2766 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2767 | |
| 2768 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2769 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2770 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2771 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2772 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2773 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2774 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2775 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2776 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2777 | rv = trans->RestartWithAuth( |
| 2778 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2779 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2780 | |
| 2781 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2782 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2783 | |
| 2784 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2785 | ASSERT_TRUE(response); |
| 2786 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2787 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2788 | } |
| 2789 | |
| 2790 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2791 | // connection, but the server gets impatient and closes the connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2792 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2793 | HttpRequestInfo request; |
| 2794 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2795 | request.url = GURL("http://www.example.org/"); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2796 | request.load_flags = 0; |
| 2797 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2798 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2799 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2800 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2801 | MockWrite( |
| 2802 | "GET / HTTP/1.1\r\n" |
| 2803 | "Host: www.example.org\r\n" |
| 2804 | "Connection: keep-alive\r\n\r\n"), |
| 2805 | // This simulates the seemingly successful write to a closed connection |
| 2806 | // if the bug is not fixed. |
| 2807 | MockWrite( |
| 2808 | "GET / HTTP/1.1\r\n" |
| 2809 | "Host: www.example.org\r\n" |
| 2810 | "Connection: keep-alive\r\n" |
| 2811 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2812 | }; |
| 2813 | |
| 2814 | MockRead data_reads1[] = { |
| 2815 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2816 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2817 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2818 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2819 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2820 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2821 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2822 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2823 | }; |
| 2824 | |
| 2825 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2826 | // be issuing -- the final header line contains the credentials. |
| 2827 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2828 | MockWrite( |
| 2829 | "GET / HTTP/1.1\r\n" |
| 2830 | "Host: www.example.org\r\n" |
| 2831 | "Connection: keep-alive\r\n" |
| 2832 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2833 | }; |
| 2834 | |
| 2835 | // Lastly, the server responds with the actual content. |
| 2836 | MockRead data_reads2[] = { |
| 2837 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2838 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2839 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2840 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2841 | }; |
| 2842 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2843 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2844 | data_writes1, arraysize(data_writes1)); |
| 2845 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2846 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2847 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2848 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2849 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2850 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2851 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2852 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2853 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2854 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2855 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2856 | |
| 2857 | rv = callback1.WaitForResult(); |
| 2858 | EXPECT_EQ(OK, rv); |
| 2859 | |
| 2860 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2861 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2862 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2863 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2864 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2865 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2866 | rv = trans->RestartWithAuth( |
| 2867 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2868 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2869 | |
| 2870 | rv = callback2.WaitForResult(); |
| 2871 | EXPECT_EQ(OK, rv); |
| 2872 | |
| 2873 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2874 | ASSERT_TRUE(response); |
| 2875 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2876 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2877 | } |
| 2878 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2879 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2880 | // that requires a restart when setting up an SSL tunnel. |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2881 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
| 2882 | HttpRequestInfo request; |
| 2883 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2884 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2885 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2886 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2887 | |
| 2888 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2889 | session_deps_.proxy_service = |
| 2890 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2891 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2892 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2893 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2894 | |
| 2895 | // Since we have proxy, should try to establish tunnel. |
| 2896 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2897 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2898 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2899 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2900 | }; |
| 2901 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2902 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2903 | // connection. |
| 2904 | MockRead data_reads1[] = { |
| 2905 | // No credentials. |
| 2906 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2907 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2908 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2909 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2910 | // Since the first connection couldn't be reused, need to establish another |
| 2911 | // once given credentials. |
| 2912 | MockWrite data_writes2[] = { |
| 2913 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2914 | // be issuing -- the final header line contains the credentials. |
| 2915 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2916 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2917 | "Proxy-Connection: keep-alive\r\n" |
| 2918 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2919 | |
| 2920 | MockWrite("GET / HTTP/1.1\r\n" |
| 2921 | "Host: www.example.org\r\n" |
| 2922 | "Connection: keep-alive\r\n\r\n"), |
| 2923 | }; |
| 2924 | |
| 2925 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2926 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 2927 | |
| 2928 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2929 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2930 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2931 | MockRead(SYNCHRONOUS, "hello"), |
| 2932 | }; |
| 2933 | |
| 2934 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2935 | data_writes1, arraysize(data_writes1)); |
| 2936 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2937 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2938 | data_writes2, arraysize(data_writes2)); |
| 2939 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2940 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 2941 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 2942 | |
| 2943 | TestCompletionCallback callback1; |
| 2944 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2945 | std::unique_ptr<HttpTransaction> trans( |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2946 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2947 | |
| 2948 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 2949 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2950 | |
| 2951 | rv = callback1.WaitForResult(); |
| 2952 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2953 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2954 | log.GetEntries(&entries); |
| 2955 | size_t pos = ExpectLogContainsSomewhere( |
| 2956 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2957 | NetLog::PHASE_NONE); |
| 2958 | ExpectLogContainsSomewhere( |
| 2959 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2960 | NetLog::PHASE_NONE); |
| 2961 | |
| 2962 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2963 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2964 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2965 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2966 | EXPECT_EQ(407, response->headers->response_code()); |
| 2967 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2968 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2969 | |
| 2970 | LoadTimingInfo load_timing_info; |
| 2971 | // CONNECT requests and responses are handled at the connect job level, so |
| 2972 | // the transaction does not yet have a connection. |
| 2973 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2974 | |
| 2975 | TestCompletionCallback callback2; |
| 2976 | |
| 2977 | rv = |
| 2978 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 2979 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2980 | |
| 2981 | rv = callback2.WaitForResult(); |
| 2982 | EXPECT_EQ(OK, rv); |
| 2983 | |
| 2984 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2985 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2986 | |
| 2987 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2988 | EXPECT_EQ(200, response->headers->response_code()); |
| 2989 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 2990 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2991 | |
| 2992 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2993 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2994 | |
| 2995 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2996 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2997 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2998 | |
| 2999 | trans.reset(); |
| 3000 | session->CloseAllConnections(); |
| 3001 | } |
| 3002 | |
| 3003 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3004 | // that requires a restart when setting up an SSL tunnel. |
| 3005 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3006 | HttpRequestInfo request; |
| 3007 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3008 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3009 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3010 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3011 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3012 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3013 | session_deps_.proxy_service = |
| 3014 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3015 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3016 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3017 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3018 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3019 | // Since we have proxy, should try to establish tunnel. |
| 3020 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3021 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3022 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3023 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3024 | }; |
| 3025 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3026 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3027 | // connection. |
| 3028 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3029 | // No credentials. |
| 3030 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3031 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3032 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3033 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3034 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3035 | MockWrite data_writes2[] = { |
| 3036 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3037 | // be issuing -- the final header line contains the credentials. |
| 3038 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3039 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3040 | "Proxy-Connection: keep-alive\r\n" |
| 3041 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3042 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3043 | MockWrite("GET / HTTP/1.1\r\n" |
| 3044 | "Host: www.example.org\r\n" |
| 3045 | "Connection: keep-alive\r\n\r\n"), |
| 3046 | }; |
| 3047 | |
| 3048 | MockRead data_reads2[] = { |
| 3049 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3050 | |
| 3051 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3052 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3053 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3054 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3055 | }; |
| 3056 | |
| 3057 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3058 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3059 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3060 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3061 | data_writes2, arraysize(data_writes2)); |
| 3062 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3063 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3064 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3065 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3066 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3067 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3068 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3069 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3070 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3071 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3072 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3073 | |
| 3074 | rv = callback1.WaitForResult(); |
| 3075 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3076 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3077 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3078 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3079 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3080 | NetLog::PHASE_NONE); |
| 3081 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3082 | entries, pos, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3083 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3084 | NetLog::PHASE_NONE); |
| 3085 | |
| 3086 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3087 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3088 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3089 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3090 | EXPECT_EQ(407, response->headers->response_code()); |
| 3091 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3092 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3093 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3094 | LoadTimingInfo load_timing_info; |
| 3095 | // CONNECT requests and responses are handled at the connect job level, so |
| 3096 | // the transaction does not yet have a connection. |
| 3097 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3098 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3099 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3100 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3101 | rv = trans->RestartWithAuth( |
| 3102 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3103 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3104 | |
| 3105 | rv = callback2.WaitForResult(); |
| 3106 | EXPECT_EQ(OK, rv); |
| 3107 | |
| 3108 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3109 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3110 | |
| 3111 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3112 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3113 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3114 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3115 | |
| 3116 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3117 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3118 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3119 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3120 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3121 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3122 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3123 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3124 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3125 | } |
| 3126 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3127 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3128 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
| 3129 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3130 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3131 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3132 | // reused. See http://crbug.com/544255. |
| 3133 | for (int i = 0; i < 2; ++i) { |
| 3134 | HttpRequestInfo request; |
| 3135 | request.method = "GET"; |
| 3136 | request.url = GURL("https://www.example.org/"); |
| 3137 | // Ensure that proxy authentication is attempted even |
| 3138 | // when the no authentication data flag is set. |
| 3139 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3140 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3141 | // Configure against proxy server "myproxy:70". |
| 3142 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 3143 | BoundTestNetLog log; |
| 3144 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3145 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3146 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3147 | std::unique_ptr<HttpTransaction> trans( |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3148 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3149 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3150 | // Since we have proxy, should try to establish tunnel. |
| 3151 | MockWrite data_writes1[] = { |
| 3152 | MockWrite(ASYNC, 0, |
| 3153 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3154 | "Host: www.example.org:443\r\n" |
| 3155 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3156 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3157 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3158 | // be issuing -- the final header line contains the credentials. |
| 3159 | MockWrite(ASYNC, 3, |
| 3160 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3161 | "Host: www.example.org:443\r\n" |
| 3162 | "Proxy-Connection: keep-alive\r\n" |
| 3163 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3164 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3165 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3166 | // The proxy responds to the connect with a 407, using a persistent |
| 3167 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3168 | MockRead data_reads1[] = { |
| 3169 | // No credentials. |
| 3170 | MockRead(ASYNC, 1, |
| 3171 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3172 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3173 | "Proxy-Connection: keep-alive\r\n" |
| 3174 | "Content-Length: 10\r\n\r\n"), |
| 3175 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3176 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3177 | // Wrong credentials (wrong password). |
| 3178 | MockRead(ASYNC, 4, |
| 3179 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3180 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3181 | "Proxy-Connection: keep-alive\r\n" |
| 3182 | "Content-Length: 10\r\n\r\n"), |
| 3183 | // No response body because the test stops reading here. |
| 3184 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3185 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3186 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3187 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3188 | arraysize(data_writes1)); |
| 3189 | data1.set_busy_before_sync_reads(true); |
| 3190 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3191 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3192 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3193 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3194 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 3195 | EXPECT_EQ(OK, callback1.GetResult(rv)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3196 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3197 | TestNetLogEntry::List entries; |
| 3198 | log.GetEntries(&entries); |
| 3199 | size_t pos = ExpectLogContainsSomewhere( |
| 3200 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3201 | NetLog::PHASE_NONE); |
| 3202 | ExpectLogContainsSomewhere( |
| 3203 | entries, pos, |
| 3204 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3205 | NetLog::PHASE_NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3206 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3207 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3208 | ASSERT_TRUE(response); |
| 3209 | ASSERT_TRUE(response->headers); |
| 3210 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3211 | EXPECT_EQ(407, response->headers->response_code()); |
| 3212 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3213 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3214 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3215 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3216 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3217 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3218 | // Wrong password (should be "bar"). |
| 3219 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3220 | callback2.callback()); |
| 3221 | EXPECT_EQ(OK, callback2.GetResult(rv)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3222 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3223 | response = trans->GetResponseInfo(); |
| 3224 | ASSERT_TRUE(response); |
| 3225 | ASSERT_TRUE(response->headers); |
| 3226 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3227 | EXPECT_EQ(407, response->headers->response_code()); |
| 3228 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3229 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3230 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3231 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3232 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3233 | // out of scope. |
| 3234 | session->CloseAllConnections(); |
| 3235 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3236 | } |
| 3237 | |
| 3238 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3239 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
| 3240 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3241 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3242 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3243 | // reused. See http://crbug.com/544255. |
| 3244 | for (int i = 0; i < 2; ++i) { |
| 3245 | HttpRequestInfo request; |
| 3246 | request.method = "GET"; |
| 3247 | request.url = GURL("https://www.example.org/"); |
| 3248 | // Ensure that proxy authentication is attempted even |
| 3249 | // when the no authentication data flag is set. |
| 3250 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3251 | |
| 3252 | // Configure against proxy server "myproxy:70". |
| 3253 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 3254 | BoundTestNetLog log; |
| 3255 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3256 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3257 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3258 | std::unique_ptr<HttpTransaction> trans( |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3259 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3260 | |
| 3261 | // Since we have proxy, should try to establish tunnel. |
| 3262 | MockWrite data_writes1[] = { |
| 3263 | MockWrite(ASYNC, 0, |
| 3264 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3265 | "Host: www.example.org:443\r\n" |
| 3266 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3267 | |
| 3268 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3269 | // be issuing -- the final header line contains the credentials. |
| 3270 | MockWrite(ASYNC, 3, |
| 3271 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3272 | "Host: www.example.org:443\r\n" |
| 3273 | "Proxy-Connection: keep-alive\r\n" |
| 3274 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3275 | }; |
| 3276 | |
| 3277 | // The proxy responds to the connect with a 407, using a persistent |
| 3278 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3279 | MockRead data_reads1[] = { |
| 3280 | // No credentials. |
| 3281 | MockRead(ASYNC, 1, |
| 3282 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3283 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3284 | "Content-Length: 10\r\n\r\n"), |
| 3285 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3286 | |
| 3287 | // Wrong credentials (wrong password). |
| 3288 | MockRead(ASYNC, 4, |
| 3289 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3290 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3291 | "Content-Length: 10\r\n\r\n"), |
| 3292 | // No response body because the test stops reading here. |
| 3293 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3294 | }; |
| 3295 | |
| 3296 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3297 | arraysize(data_writes1)); |
| 3298 | data1.set_busy_before_sync_reads(true); |
| 3299 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3300 | |
| 3301 | TestCompletionCallback callback1; |
| 3302 | |
| 3303 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 3304 | EXPECT_EQ(OK, callback1.GetResult(rv)); |
| 3305 | |
| 3306 | TestNetLogEntry::List entries; |
| 3307 | log.GetEntries(&entries); |
| 3308 | size_t pos = ExpectLogContainsSomewhere( |
| 3309 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3310 | NetLog::PHASE_NONE); |
| 3311 | ExpectLogContainsSomewhere( |
| 3312 | entries, pos, |
| 3313 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3314 | NetLog::PHASE_NONE); |
| 3315 | |
| 3316 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3317 | ASSERT_TRUE(response); |
| 3318 | ASSERT_TRUE(response->headers); |
| 3319 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3320 | EXPECT_EQ(407, response->headers->response_code()); |
| 3321 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3322 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3323 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3324 | |
| 3325 | TestCompletionCallback callback2; |
| 3326 | |
| 3327 | // Wrong password (should be "bar"). |
| 3328 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3329 | callback2.callback()); |
| 3330 | EXPECT_EQ(OK, callback2.GetResult(rv)); |
| 3331 | |
| 3332 | response = trans->GetResponseInfo(); |
| 3333 | ASSERT_TRUE(response); |
| 3334 | ASSERT_TRUE(response->headers); |
| 3335 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3336 | EXPECT_EQ(407, response->headers->response_code()); |
| 3337 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3338 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3339 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3340 | |
| 3341 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3342 | // out of scope. |
| 3343 | session->CloseAllConnections(); |
| 3344 | } |
| 3345 | } |
| 3346 | |
| 3347 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3348 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3349 | // the case the server sends extra data on the original socket, so it can't be |
| 3350 | // reused. |
| 3351 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3352 | HttpRequestInfo request; |
| 3353 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3354 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3355 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3356 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3357 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3358 | // Configure against proxy server "myproxy:70". |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3359 | session_deps_.proxy_service = |
| 3360 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3361 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3362 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3363 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3364 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3365 | // Since we have proxy, should try to establish tunnel. |
| 3366 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3367 | MockWrite(ASYNC, 0, |
| 3368 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3369 | "Host: www.example.org:443\r\n" |
| 3370 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3371 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3372 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3373 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3374 | // extra data, so the socket cannot be reused. |
| 3375 | MockRead data_reads1[] = { |
| 3376 | // No credentials. |
| 3377 | MockRead(ASYNC, 1, |
| 3378 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3379 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3380 | "Content-Length: 10\r\n\r\n"), |
| 3381 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3382 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3383 | }; |
| 3384 | |
| 3385 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3386 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3387 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3388 | MockWrite(ASYNC, 0, |
| 3389 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3390 | "Host: www.example.org:443\r\n" |
| 3391 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3392 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3393 | |
| 3394 | MockWrite(ASYNC, 2, |
| 3395 | "GET / HTTP/1.1\r\n" |
| 3396 | "Host: www.example.org\r\n" |
| 3397 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3398 | }; |
| 3399 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3400 | MockRead data_reads2[] = { |
| 3401 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3402 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3403 | MockRead(ASYNC, 3, |
| 3404 | "HTTP/1.1 200 OK\r\n" |
| 3405 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3406 | "Content-Length: 5\r\n\r\n"), |
| 3407 | // No response body because the test stops reading here. |
| 3408 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3409 | }; |
| 3410 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3411 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3412 | arraysize(data_writes1)); |
| 3413 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3414 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3415 | SequencedSocketData data2(data_reads2, arraysize(data_reads2), data_writes2, |
| 3416 | arraysize(data_writes2)); |
| 3417 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3418 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3419 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3420 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3421 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3422 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3423 | std::unique_ptr<HttpTransaction> trans( |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3424 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3425 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3426 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 3427 | EXPECT_EQ(OK, callback1.GetResult(rv)); |
| 3428 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3429 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3430 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3431 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3432 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3433 | NetLog::PHASE_NONE); |
| 3434 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3435 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3436 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3437 | NetLog::PHASE_NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3438 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3439 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3440 | ASSERT_TRUE(response); |
| 3441 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3442 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3443 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3444 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3445 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3446 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3447 | LoadTimingInfo load_timing_info; |
| 3448 | // CONNECT requests and responses are handled at the connect job level, so |
| 3449 | // the transaction does not yet have a connection. |
| 3450 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3451 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3452 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3453 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3454 | rv = |
| 3455 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 3456 | EXPECT_EQ(OK, callback2.GetResult(rv)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3457 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3458 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3459 | EXPECT_EQ(200, response->headers->response_code()); |
| 3460 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3461 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3462 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3463 | // The password prompt info should not be set. |
| 3464 | EXPECT_FALSE(response->auth_challenge); |
| 3465 | |
| 3466 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3467 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3468 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3469 | |
| 3470 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3471 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3472 | } |
| 3473 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3474 | // Test the case a proxy closes a socket while the challenge body is being |
| 3475 | // drained. |
| 3476 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
| 3477 | HttpRequestInfo request; |
| 3478 | request.method = "GET"; |
| 3479 | request.url = GURL("https://www.example.org/"); |
| 3480 | // Ensure that proxy authentication is attempted even |
| 3481 | // when the no authentication data flag is set. |
| 3482 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3483 | |
| 3484 | // Configure against proxy server "myproxy:70". |
| 3485 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3486 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3487 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3488 | std::unique_ptr<HttpTransaction> trans( |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3489 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3490 | |
| 3491 | // Since we have proxy, should try to establish tunnel. |
| 3492 | MockWrite data_writes1[] = { |
| 3493 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3494 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3495 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3496 | }; |
| 3497 | |
| 3498 | // The proxy responds to the connect with a 407, using a persistent |
| 3499 | // connection. |
| 3500 | MockRead data_reads1[] = { |
| 3501 | // No credentials. |
| 3502 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3503 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3504 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3505 | // Server hands up in the middle of the body. |
| 3506 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3507 | }; |
| 3508 | |
| 3509 | MockWrite data_writes2[] = { |
| 3510 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3511 | // be issuing -- the final header line contains the credentials. |
| 3512 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3513 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3514 | "Proxy-Connection: keep-alive\r\n" |
| 3515 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3516 | |
| 3517 | MockWrite("GET / HTTP/1.1\r\n" |
| 3518 | "Host: www.example.org\r\n" |
| 3519 | "Connection: keep-alive\r\n\r\n"), |
| 3520 | }; |
| 3521 | |
| 3522 | MockRead data_reads2[] = { |
| 3523 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3524 | |
| 3525 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3526 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3527 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3528 | MockRead(SYNCHRONOUS, "hello"), |
| 3529 | }; |
| 3530 | |
| 3531 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3532 | data_writes1, arraysize(data_writes1)); |
| 3533 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3534 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3535 | data_writes2, arraysize(data_writes2)); |
| 3536 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3537 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3538 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3539 | |
| 3540 | TestCompletionCallback callback; |
| 3541 | |
| 3542 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3543 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3544 | |
| 3545 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3546 | ASSERT_TRUE(response); |
| 3547 | ASSERT_TRUE(response->headers); |
| 3548 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3549 | EXPECT_EQ(407, response->headers->response_code()); |
| 3550 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3551 | |
| 3552 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 3553 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3554 | |
| 3555 | response = trans->GetResponseInfo(); |
| 3556 | ASSERT_TRUE(response); |
| 3557 | ASSERT_TRUE(response->headers); |
| 3558 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3559 | EXPECT_EQ(200, response->headers->response_code()); |
| 3560 | std::string body; |
| 3561 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &body)); |
| 3562 | EXPECT_EQ("hello", body); |
| 3563 | } |
| 3564 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3565 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3566 | // even if the user cancels the proxy's auth attempt. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3567 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3568 | HttpRequestInfo request; |
| 3569 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3570 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3571 | request.load_flags = 0; |
| 3572 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3573 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3574 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3575 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3576 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3577 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3578 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3579 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3580 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3581 | // Since we have proxy, should try to establish tunnel. |
| 3582 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3583 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3584 | "Host: www.example.org:443\r\n" |
| 3585 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3586 | }; |
| 3587 | |
| 3588 | // The proxy responds to the connect with a 407. |
| 3589 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3590 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3591 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3592 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3593 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3594 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3595 | }; |
| 3596 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3597 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 3598 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3599 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3600 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3601 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3602 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3603 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3604 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3605 | |
| 3606 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3607 | EXPECT_EQ(OK, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3608 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3609 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3610 | ASSERT_TRUE(response); |
| 3611 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3612 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3613 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3614 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3615 | |
| 3616 | std::string response_data; |
| 3617 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3618 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3619 | |
| 3620 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3621 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3622 | } |
| 3623 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3624 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3625 | // caller when the proxy responds to CONNECT with 407. |
| 3626 | TEST_P(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
| 3627 | HttpRequestInfo request; |
| 3628 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3629 | request.url = GURL("https://www.example.org/"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3630 | request.load_flags = 0; |
| 3631 | |
| 3632 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3633 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3634 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3635 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3636 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3637 | std::unique_ptr<HttpTransaction> trans( |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3638 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3639 | |
| 3640 | // Since we have proxy, should try to establish tunnel. |
| 3641 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3642 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3643 | "Host: www.example.org:443\r\n" |
| 3644 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3645 | }; |
| 3646 | |
| 3647 | // The proxy responds to the connect with a 407. |
| 3648 | MockRead data_reads[] = { |
| 3649 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3650 | MockRead("X-Foo: bar\r\n"), |
| 3651 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 3652 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3653 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3654 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3655 | }; |
| 3656 | |
| 3657 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 3658 | arraysize(data_writes)); |
| 3659 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3660 | |
| 3661 | TestCompletionCallback callback; |
| 3662 | |
| 3663 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3664 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3665 | |
| 3666 | rv = callback.WaitForResult(); |
| 3667 | EXPECT_EQ(OK, rv); |
| 3668 | |
| 3669 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3670 | ASSERT_TRUE(response); |
| 3671 | ASSERT_TRUE(response->headers); |
| 3672 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3673 | EXPECT_EQ(407, response->headers->response_code()); |
| 3674 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3675 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 3676 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 3677 | |
| 3678 | std::string response_data; |
| 3679 | rv = ReadTransaction(trans.get(), &response_data); |
| 3680 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 3681 | |
| 3682 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 3683 | session->CloseAllConnections(); |
| 3684 | } |
| 3685 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3686 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 3687 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3688 | TEST_P(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3689 | HttpRequestInfo request; |
| 3690 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3691 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3692 | request.load_flags = 0; |
| 3693 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3694 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3695 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 3696 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 3697 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3698 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3699 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3700 | MockWrite( |
| 3701 | "GET / HTTP/1.1\r\n" |
| 3702 | "Host: www.example.org\r\n" |
| 3703 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3704 | }; |
| 3705 | |
| 3706 | MockRead data_reads1[] = { |
| 3707 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 3708 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3709 | // Large content-length -- won't matter, as connection will be reset. |
| 3710 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3711 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3712 | }; |
| 3713 | |
| 3714 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3715 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3716 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3717 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3718 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3719 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3720 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3721 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3722 | |
| 3723 | rv = callback.WaitForResult(); |
| 3724 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
| 3725 | } |
| 3726 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3727 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3728 | // through a non-authenticating proxy. The request should fail with |
| 3729 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3730 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3731 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3732 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3733 | // issued the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3734 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3735 | HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3736 | HttpRequestInfo request; |
| 3737 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3738 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3739 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3740 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3741 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3742 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3743 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3744 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3745 | // Since we have proxy, should try to establish tunnel. |
| 3746 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3747 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3748 | "Host: www.example.org:443\r\n" |
| 3749 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3750 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3751 | MockWrite("GET / HTTP/1.1\r\n" |
| 3752 | "Host: www.example.org\r\n" |
| 3753 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3754 | }; |
| 3755 | |
| 3756 | MockRead data_reads1[] = { |
| 3757 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3758 | |
| 3759 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3760 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3761 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3762 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3763 | }; |
| 3764 | |
| 3765 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3766 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3767 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3768 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3769 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3770 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3771 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3772 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3773 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3774 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3775 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3776 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3777 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3778 | |
| 3779 | rv = callback1.WaitForResult(); |
| 3780 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3781 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3782 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3783 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3784 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3785 | NetLog::PHASE_NONE); |
| 3786 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3787 | entries, pos, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3788 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3789 | NetLog::PHASE_NONE); |
| 3790 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3791 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3792 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3793 | // that uses non-persistent connections. |
| 3794 | TEST_P(HttpNetworkTransactionTest, |
| 3795 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 3796 | HttpRequestInfo request; |
| 3797 | request.method = "GET"; |
| 3798 | request.url = GURL("https://www.example.org/"); |
| 3799 | |
| 3800 | // Configure against proxy server "myproxy:70". |
| 3801 | session_deps_.proxy_service = |
| 3802 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3803 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3804 | std::unique_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3805 | new HttpAuthHandlerMock::Factory()); |
| 3806 | auth_handler_factory->set_do_init_from_challenge(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3807 | std::unique_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3808 | mock_handler->set_allows_default_credentials(true); |
| 3809 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3810 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3811 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3812 | |
| 3813 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3814 | NetLog net_log; |
| 3815 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3816 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3817 | |
| 3818 | // Since we have proxy, should try to establish tunnel. |
| 3819 | MockWrite data_writes1[] = { |
| 3820 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3821 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3822 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3823 | }; |
| 3824 | |
| 3825 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3826 | // connection. |
| 3827 | MockRead data_reads1[] = { |
| 3828 | // No credentials. |
| 3829 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3830 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3831 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3832 | }; |
| 3833 | |
| 3834 | // Since the first connection couldn't be reused, need to establish another |
| 3835 | // once given credentials. |
| 3836 | MockWrite data_writes2[] = { |
| 3837 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3838 | // be issuing -- the final header line contains the credentials. |
| 3839 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3840 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3841 | "Proxy-Connection: keep-alive\r\n" |
| 3842 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3843 | |
| 3844 | MockWrite("GET / HTTP/1.1\r\n" |
| 3845 | "Host: www.example.org\r\n" |
| 3846 | "Connection: keep-alive\r\n\r\n"), |
| 3847 | }; |
| 3848 | |
| 3849 | MockRead data_reads2[] = { |
| 3850 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3851 | |
| 3852 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3853 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3854 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3855 | MockRead(SYNCHRONOUS, "hello"), |
| 3856 | }; |
| 3857 | |
| 3858 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3859 | data_writes1, arraysize(data_writes1)); |
| 3860 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3861 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3862 | data_writes2, arraysize(data_writes2)); |
| 3863 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3864 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3865 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3866 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3867 | std::unique_ptr<HttpTransaction> trans( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3868 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3869 | |
| 3870 | TestCompletionCallback callback; |
| 3871 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3872 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3873 | |
| 3874 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3875 | ASSERT_TRUE(response); |
| 3876 | ASSERT_TRUE(response->headers); |
| 3877 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 3878 | EXPECT_EQ(407, response->headers->response_code()); |
| 3879 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3880 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3881 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3882 | |
| 3883 | LoadTimingInfo load_timing_info; |
| 3884 | // CONNECT requests and responses are handled at the connect job level, so |
| 3885 | // the transaction does not yet have a connection. |
| 3886 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3887 | |
| 3888 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 3889 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3890 | response = trans->GetResponseInfo(); |
| 3891 | ASSERT_TRUE(response); |
| 3892 | ASSERT_TRUE(response->headers); |
| 3893 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3894 | EXPECT_EQ(200, response->headers->response_code()); |
| 3895 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3896 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3897 | |
| 3898 | // The password prompt info should not be set. |
| 3899 | EXPECT_FALSE(response->auth_challenge); |
| 3900 | |
| 3901 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3902 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3903 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3904 | |
| 3905 | trans.reset(); |
| 3906 | session->CloseAllConnections(); |
| 3907 | } |
| 3908 | |
| 3909 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3910 | // that hangs up when credentials are initially sent. |
| 3911 | TEST_P(HttpNetworkTransactionTest, |
| 3912 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 3913 | HttpRequestInfo request; |
| 3914 | request.method = "GET"; |
| 3915 | request.url = GURL("https://www.example.org/"); |
| 3916 | |
| 3917 | // Configure against proxy server "myproxy:70". |
| 3918 | session_deps_.proxy_service = |
| 3919 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3920 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3921 | std::unique_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3922 | new HttpAuthHandlerMock::Factory()); |
| 3923 | auth_handler_factory->set_do_init_from_challenge(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3924 | std::unique_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3925 | mock_handler->set_allows_default_credentials(true); |
| 3926 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3927 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3928 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3929 | |
| 3930 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3931 | NetLog net_log; |
| 3932 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3933 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3934 | |
| 3935 | // Should try to establish tunnel. |
| 3936 | MockWrite data_writes1[] = { |
| 3937 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3938 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3939 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3940 | |
| 3941 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3942 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3943 | "Proxy-Connection: keep-alive\r\n" |
| 3944 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3945 | }; |
| 3946 | |
| 3947 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3948 | // connection. |
| 3949 | MockRead data_reads1[] = { |
| 3950 | // No credentials. |
| 3951 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3952 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 3953 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 3954 | }; |
| 3955 | |
| 3956 | // Since the first connection was closed, need to establish another once given |
| 3957 | // credentials. |
| 3958 | MockWrite data_writes2[] = { |
| 3959 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3960 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3961 | "Proxy-Connection: keep-alive\r\n" |
| 3962 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3963 | |
| 3964 | MockWrite("GET / HTTP/1.1\r\n" |
| 3965 | "Host: www.example.org\r\n" |
| 3966 | "Connection: keep-alive\r\n\r\n"), |
| 3967 | }; |
| 3968 | |
| 3969 | MockRead data_reads2[] = { |
| 3970 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3971 | |
| 3972 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3973 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3974 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3975 | MockRead(SYNCHRONOUS, "hello"), |
| 3976 | }; |
| 3977 | |
| 3978 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3979 | data_writes1, arraysize(data_writes1)); |
| 3980 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3981 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3982 | data_writes2, arraysize(data_writes2)); |
| 3983 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3984 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3985 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3986 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3987 | std::unique_ptr<HttpTransaction> trans( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3988 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3989 | |
| 3990 | TestCompletionCallback callback; |
| 3991 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3992 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3993 | |
| 3994 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3995 | ASSERT_TRUE(response); |
| 3996 | ASSERT_TRUE(response->headers); |
| 3997 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3998 | EXPECT_EQ(407, response->headers->response_code()); |
| 3999 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4000 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4001 | EXPECT_FALSE(response->auth_challenge); |
| 4002 | |
| 4003 | LoadTimingInfo load_timing_info; |
| 4004 | // CONNECT requests and responses are handled at the connect job level, so |
| 4005 | // the transaction does not yet have a connection. |
| 4006 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4007 | |
| 4008 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4009 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 4010 | |
| 4011 | response = trans->GetResponseInfo(); |
| 4012 | ASSERT_TRUE(response); |
| 4013 | ASSERT_TRUE(response->headers); |
| 4014 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4015 | EXPECT_EQ(200, response->headers->response_code()); |
| 4016 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4017 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4018 | |
| 4019 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4020 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4021 | |
| 4022 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4023 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4024 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4025 | |
| 4026 | trans.reset(); |
| 4027 | session->CloseAllConnections(); |
| 4028 | } |
| 4029 | |
| 4030 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4031 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4032 | // they are retried. |
| 4033 | TEST_P(HttpNetworkTransactionTest, |
| 4034 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4035 | HttpRequestInfo request; |
| 4036 | request.method = "GET"; |
| 4037 | request.url = GURL("https://www.example.org/"); |
| 4038 | |
| 4039 | // Configure against proxy server "myproxy:70". |
| 4040 | session_deps_.proxy_service = |
| 4041 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 4042 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4043 | std::unique_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4044 | new HttpAuthHandlerMock::Factory()); |
| 4045 | auth_handler_factory->set_do_init_from_challenge(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4046 | std::unique_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4047 | mock_handler->set_allows_default_credentials(true); |
| 4048 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4049 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4050 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4051 | |
| 4052 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4053 | NetLog net_log; |
| 4054 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4055 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4056 | |
| 4057 | // Should try to establish tunnel. |
| 4058 | MockWrite data_writes1[] = { |
| 4059 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4060 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4061 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4062 | |
| 4063 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4064 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4065 | "Proxy-Connection: keep-alive\r\n" |
| 4066 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4067 | }; |
| 4068 | |
| 4069 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4070 | // second request is sent. |
| 4071 | MockRead data_reads1[] = { |
| 4072 | // No credentials. |
| 4073 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4074 | MockRead("Content-Length: 0\r\n"), |
| 4075 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4076 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4077 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4078 | }; |
| 4079 | |
| 4080 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4081 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4082 | // request. |
| 4083 | MockWrite data_writes2[] = { |
| 4084 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4085 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4086 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4087 | }; |
| 4088 | |
| 4089 | // The proxy, having had more than enough of us, just hangs up. |
| 4090 | MockRead data_reads2[] = { |
| 4091 | // No credentials. |
| 4092 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4093 | }; |
| 4094 | |
| 4095 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4096 | data_writes1, arraysize(data_writes1)); |
| 4097 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4098 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4099 | data_writes2, arraysize(data_writes2)); |
| 4100 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4101 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4102 | std::unique_ptr<HttpTransaction> trans( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4103 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 4104 | |
| 4105 | TestCompletionCallback callback; |
| 4106 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 4107 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 4108 | |
| 4109 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4110 | ASSERT_TRUE(response); |
| 4111 | ASSERT_TRUE(response->headers); |
| 4112 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4113 | EXPECT_EQ(407, response->headers->response_code()); |
| 4114 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4115 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4116 | EXPECT_FALSE(response->auth_challenge); |
| 4117 | |
| 4118 | LoadTimingInfo load_timing_info; |
| 4119 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4120 | |
| 4121 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4122 | EXPECT_EQ(ERR_EMPTY_RESPONSE, callback.GetResult(rv)); |
| 4123 | |
| 4124 | trans.reset(); |
| 4125 | session->CloseAllConnections(); |
| 4126 | } |
| 4127 | |
| 4128 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4129 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4130 | // again they are retried. |
| 4131 | TEST_P(HttpNetworkTransactionTest, |
| 4132 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4133 | HttpRequestInfo request; |
| 4134 | request.method = "GET"; |
| 4135 | request.url = GURL("https://www.example.org/"); |
| 4136 | |
| 4137 | // Configure against proxy server "myproxy:70". |
| 4138 | session_deps_.proxy_service = |
| 4139 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 4140 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4141 | std::unique_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4142 | new HttpAuthHandlerMock::Factory()); |
| 4143 | auth_handler_factory->set_do_init_from_challenge(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4144 | std::unique_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4145 | mock_handler->set_allows_default_credentials(true); |
| 4146 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4147 | HttpAuth::AUTH_PROXY); |
| 4148 | // Add another handler for the second challenge. It supports default |
| 4149 | // credentials, but they shouldn't be used, since they were already tried. |
| 4150 | mock_handler.reset(new HttpAuthHandlerMock()); |
| 4151 | mock_handler->set_allows_default_credentials(true); |
| 4152 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4153 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4154 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4155 | |
| 4156 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4157 | NetLog net_log; |
| 4158 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4159 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4160 | |
| 4161 | // Should try to establish tunnel. |
| 4162 | MockWrite data_writes1[] = { |
| 4163 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4164 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4165 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4166 | }; |
| 4167 | |
| 4168 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4169 | // connection. |
| 4170 | MockRead data_reads1[] = { |
| 4171 | // No credentials. |
| 4172 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4173 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4174 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4175 | }; |
| 4176 | |
| 4177 | // Since the first connection was closed, need to establish another once given |
| 4178 | // credentials. |
| 4179 | MockWrite data_writes2[] = { |
| 4180 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4181 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4182 | "Proxy-Connection: keep-alive\r\n" |
| 4183 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4184 | }; |
| 4185 | |
| 4186 | MockRead data_reads2[] = { |
| 4187 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4188 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4189 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4190 | }; |
| 4191 | |
| 4192 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4193 | data_writes1, arraysize(data_writes1)); |
| 4194 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4195 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4196 | data_writes2, arraysize(data_writes2)); |
| 4197 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4198 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4199 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4200 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4201 | std::unique_ptr<HttpTransaction> trans( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4202 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 4203 | |
| 4204 | TestCompletionCallback callback; |
| 4205 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 4206 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 4207 | |
| 4208 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4209 | ASSERT_TRUE(response); |
| 4210 | ASSERT_TRUE(response->headers); |
| 4211 | EXPECT_EQ(407, response->headers->response_code()); |
| 4212 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4213 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4214 | EXPECT_FALSE(response->auth_challenge); |
| 4215 | |
| 4216 | LoadTimingInfo load_timing_info; |
| 4217 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4218 | |
| 4219 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4220 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 4221 | response = trans->GetResponseInfo(); |
| 4222 | ASSERT_TRUE(response); |
| 4223 | ASSERT_TRUE(response->headers); |
| 4224 | EXPECT_EQ(407, response->headers->response_code()); |
| 4225 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4226 | EXPECT_TRUE(response->auth_challenge); |
| 4227 | |
| 4228 | trans.reset(); |
| 4229 | session->CloseAllConnections(); |
| 4230 | } |
| 4231 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4232 | // Test the load timing for HTTPS requests with an HTTP proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4233 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4234 | HttpRequestInfo request1; |
| 4235 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4236 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4237 | |
| 4238 | HttpRequestInfo request2; |
| 4239 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4240 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4241 | |
| 4242 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4243 | session_deps_.proxy_service = ProxyService::CreateFixed("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4244 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4245 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4246 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4247 | |
| 4248 | // Since we have proxy, should try to establish tunnel. |
| 4249 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4250 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4251 | "Host: www.example.org:443\r\n" |
| 4252 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4253 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4254 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4255 | "Host: www.example.org\r\n" |
| 4256 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4257 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4258 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4259 | "Host: www.example.org\r\n" |
| 4260 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4261 | }; |
| 4262 | |
| 4263 | // The proxy responds to the connect with a 407, using a persistent |
| 4264 | // connection. |
| 4265 | MockRead data_reads1[] = { |
| 4266 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4267 | |
| 4268 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4269 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4270 | MockRead(SYNCHRONOUS, "1"), |
| 4271 | |
| 4272 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4273 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4274 | MockRead(SYNCHRONOUS, "22"), |
| 4275 | }; |
| 4276 | |
| 4277 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4278 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4279 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4280 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4281 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4282 | |
| 4283 | TestCompletionCallback callback1; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4284 | std::unique_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4285 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4286 | |
| 4287 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 4288 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4289 | |
| 4290 | rv = callback1.WaitForResult(); |
| 4291 | EXPECT_EQ(OK, rv); |
| 4292 | |
| 4293 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4294 | ASSERT_TRUE(response1); |
| 4295 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4296 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4297 | |
| 4298 | LoadTimingInfo load_timing_info1; |
| 4299 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4300 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4301 | |
| 4302 | trans1.reset(); |
| 4303 | |
| 4304 | TestCompletionCallback callback2; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4305 | std::unique_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4306 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4307 | |
| 4308 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 4309 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4310 | |
| 4311 | rv = callback2.WaitForResult(); |
| 4312 | EXPECT_EQ(OK, rv); |
| 4313 | |
| 4314 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4315 | ASSERT_TRUE(response2); |
| 4316 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4317 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4318 | |
| 4319 | LoadTimingInfo load_timing_info2; |
| 4320 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4321 | TestLoadTimingReused(load_timing_info2); |
| 4322 | |
| 4323 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4324 | |
| 4325 | trans2.reset(); |
| 4326 | session->CloseAllConnections(); |
| 4327 | } |
| 4328 | |
| 4329 | // 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] | 4330 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4331 | HttpRequestInfo request1; |
| 4332 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4333 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4334 | |
| 4335 | HttpRequestInfo request2; |
| 4336 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4337 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4338 | |
| 4339 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4340 | session_deps_.proxy_service = |
| 4341 | ProxyService::CreateFixedFromPacResult("PROXY 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(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4344 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4345 | |
| 4346 | // Since we have proxy, should try to establish tunnel. |
| 4347 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4348 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4349 | "Host: www.example.org:443\r\n" |
| 4350 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4351 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4352 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4353 | "Host: www.example.org\r\n" |
| 4354 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4355 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4356 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4357 | "Host: www.example.org\r\n" |
| 4358 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4359 | }; |
| 4360 | |
| 4361 | // The proxy responds to the connect with a 407, using a persistent |
| 4362 | // connection. |
| 4363 | MockRead data_reads1[] = { |
| 4364 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4365 | |
| 4366 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4367 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4368 | MockRead(SYNCHRONOUS, "1"), |
| 4369 | |
| 4370 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4371 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4372 | MockRead(SYNCHRONOUS, "22"), |
| 4373 | }; |
| 4374 | |
| 4375 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4376 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4377 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4378 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4379 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4380 | |
| 4381 | TestCompletionCallback callback1; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4382 | std::unique_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4383 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4384 | |
| 4385 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 4386 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4387 | |
| 4388 | rv = callback1.WaitForResult(); |
| 4389 | EXPECT_EQ(OK, rv); |
| 4390 | |
| 4391 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4392 | ASSERT_TRUE(response1); |
| 4393 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4394 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4395 | |
| 4396 | LoadTimingInfo load_timing_info1; |
| 4397 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4398 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 4399 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4400 | |
| 4401 | trans1.reset(); |
| 4402 | |
| 4403 | TestCompletionCallback callback2; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4404 | std::unique_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4405 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4406 | |
| 4407 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 4408 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4409 | |
| 4410 | rv = callback2.WaitForResult(); |
| 4411 | EXPECT_EQ(OK, rv); |
| 4412 | |
| 4413 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4414 | ASSERT_TRUE(response2); |
| 4415 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4416 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4417 | |
| 4418 | LoadTimingInfo load_timing_info2; |
| 4419 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4420 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 4421 | |
| 4422 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4423 | |
| 4424 | trans2.reset(); |
| 4425 | session->CloseAllConnections(); |
| 4426 | } |
| 4427 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4428 | // Test a simple get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4429 | TEST_P(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4430 | HttpRequestInfo request; |
| 4431 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4432 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4433 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4434 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4435 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4436 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4437 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4438 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4439 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4440 | // Since we have proxy, should use full url |
| 4441 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4442 | MockWrite( |
| 4443 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4444 | "Host: www.example.org\r\n" |
| 4445 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4446 | }; |
| 4447 | |
| 4448 | MockRead data_reads1[] = { |
| 4449 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4450 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4451 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4452 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4453 | }; |
| 4454 | |
| 4455 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4456 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4457 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4458 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4459 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4460 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4461 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4462 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4463 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4464 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4465 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4466 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4467 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4468 | |
| 4469 | rv = callback1.WaitForResult(); |
| 4470 | EXPECT_EQ(OK, rv); |
| 4471 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4472 | LoadTimingInfo load_timing_info; |
| 4473 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4474 | TestLoadTimingNotReused(load_timing_info, |
| 4475 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4476 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4477 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4478 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4479 | |
| 4480 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4481 | EXPECT_EQ(200, response->headers->response_code()); |
| 4482 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4483 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4484 | |
| 4485 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4486 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4487 | } |
| 4488 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4489 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4490 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4491 | HttpRequestInfo request; |
| 4492 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4493 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4494 | request.load_flags = 0; |
| 4495 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4496 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4497 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4498 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4499 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4500 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4501 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4502 | // fetch http://www.example.org/ via SPDY |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4503 | std::unique_ptr<SpdySerializedFrame> req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4504 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, false)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4505 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4506 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4507 | std::unique_ptr<SpdySerializedFrame> resp( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 4508 | spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4509 | std::unique_ptr<SpdySerializedFrame> data( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 4510 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4511 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4512 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4513 | }; |
| 4514 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4515 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4516 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4517 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4518 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4519 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4520 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4521 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4522 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4523 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4524 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4525 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4526 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4527 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4528 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4529 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4530 | |
| 4531 | rv = callback1.WaitForResult(); |
| 4532 | EXPECT_EQ(OK, rv); |
| 4533 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4534 | LoadTimingInfo load_timing_info; |
| 4535 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4536 | TestLoadTimingNotReused(load_timing_info, |
| 4537 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4538 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4539 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4540 | ASSERT_TRUE(response); |
| 4541 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4542 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4543 | |
| 4544 | std::string response_data; |
| 4545 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4546 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4547 | } |
| 4548 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4549 | // Verifies that a session which races and wins against the owning transaction |
| 4550 | // (completing prior to host resolution), doesn't fail the transaction. |
| 4551 | // Regression test for crbug.com/334413. |
| 4552 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
| 4553 | HttpRequestInfo request; |
| 4554 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4555 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4556 | request.load_flags = 0; |
| 4557 | |
| 4558 | // Configure SPDY proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4559 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4560 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4561 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4562 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4563 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4564 | // Fetch http://www.example.org/ through the SPDY proxy. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4565 | std::unique_ptr<SpdySerializedFrame> req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4566 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, false)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4567 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4568 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4569 | std::unique_ptr<SpdySerializedFrame> resp( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 4570 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4571 | std::unique_ptr<SpdySerializedFrame> data( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 4572 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4573 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4574 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4575 | }; |
| 4576 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4577 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4578 | arraysize(spdy_writes)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4579 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 4580 | |
| 4581 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4582 | ssl.SetNextProto(GetProtocol()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4583 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4584 | |
| 4585 | TestCompletionCallback callback1; |
| 4586 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4587 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4588 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 4589 | |
| 4590 | // Stall the hostname resolution begun by the transaction. |
| 4591 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 4592 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4593 | |
| 4594 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 4595 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4596 | |
| 4597 | // Race a session to the proxy, which completes first. |
| 4598 | session_deps_.host_resolver->set_ondemand_mode(false); |
| 4599 | SpdySessionKey key( |
| 4600 | HostPortPair("proxy", 70), ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 4601 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4602 | CreateSecureSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4603 | |
| 4604 | // Unstall the resolution begun by the transaction. |
| 4605 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4606 | session_deps_.host_resolver->ResolveAllPending(); |
| 4607 | |
| 4608 | EXPECT_FALSE(callback1.have_result()); |
| 4609 | rv = callback1.WaitForResult(); |
| 4610 | EXPECT_EQ(OK, rv); |
| 4611 | |
| 4612 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4613 | ASSERT_TRUE(response); |
| 4614 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4615 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4616 | |
| 4617 | std::string response_data; |
| 4618 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 4619 | EXPECT_EQ(kUploadData, response_data); |
| 4620 | } |
| 4621 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4622 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4623 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4624 | HttpRequestInfo request; |
| 4625 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4626 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4627 | request.load_flags = 0; |
| 4628 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4629 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4630 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4631 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4632 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4633 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4634 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4635 | // The first request will be a bare GET, the second request will be a |
| 4636 | // GET with a Proxy-Authorization header. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4637 | std::unique_ptr<SpdySerializedFrame> req_get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4638 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, false)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4639 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4640 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4641 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4642 | }; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4643 | std::unique_ptr<SpdySerializedFrame> req_get_authorization( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4644 | spdy_util_.ConstructSpdyGet(kExtraAuthorizationHeaders, |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 4645 | arraysize(kExtraAuthorizationHeaders) / 2, 3, |
| 4646 | LOWEST, false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4647 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4648 | CreateMockWrite(*req_get, 0), CreateMockWrite(*req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4649 | }; |
| 4650 | |
| 4651 | // The first response is a 407 proxy authentication challenge, and the second |
| 4652 | // response will be a 200 response since the second request includes a valid |
| 4653 | // Authorization header. |
| 4654 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4655 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4656 | }; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4657 | std::unique_ptr<SpdySerializedFrame> resp_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4658 | spdy_util_.ConstructSpdySynReplyError( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 4659 | "407 Proxy Authentication Required", kExtraAuthenticationHeaders, |
| 4660 | arraysize(kExtraAuthenticationHeaders) / 2, 1)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4661 | std::unique_ptr<SpdySerializedFrame> body_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4662 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4663 | std::unique_ptr<SpdySerializedFrame> resp_data( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4664 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4665 | std::unique_ptr<SpdySerializedFrame> body_data( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 4666 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4667 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4668 | CreateMockRead(*resp_authentication, 1), |
| 4669 | CreateMockRead(*body_authentication, 2), |
| 4670 | CreateMockRead(*resp_data, 4), |
| 4671 | CreateMockRead(*body_data, 5), |
| 4672 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4673 | }; |
| 4674 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4675 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4676 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4677 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4678 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4679 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4680 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4681 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4682 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4683 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4684 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4685 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4686 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4687 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4688 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4689 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4690 | |
| 4691 | rv = callback1.WaitForResult(); |
| 4692 | EXPECT_EQ(OK, rv); |
| 4693 | |
| 4694 | const HttpResponseInfo* const response = trans->GetResponseInfo(); |
| 4695 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4696 | ASSERT_TRUE(response); |
| 4697 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4698 | EXPECT_EQ(407, response->headers->response_code()); |
| 4699 | EXPECT_TRUE(response->was_fetched_via_spdy); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4700 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4701 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4702 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4703 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4704 | rv = trans->RestartWithAuth( |
| 4705 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4706 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4707 | |
| 4708 | rv = callback2.WaitForResult(); |
| 4709 | EXPECT_EQ(OK, rv); |
| 4710 | |
| 4711 | const HttpResponseInfo* const response_restart = trans->GetResponseInfo(); |
| 4712 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4713 | ASSERT_TRUE(response_restart); |
| 4714 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4715 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 4716 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4717 | EXPECT_FALSE(response_restart->auth_challenge); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4718 | } |
| 4719 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4720 | // 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] | 4721 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4722 | HttpRequestInfo request; |
| 4723 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4724 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4725 | request.load_flags = 0; |
| 4726 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4727 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4728 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4729 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4730 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4731 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4732 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4733 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4734 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4735 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4736 | // CONNECT to www.example.org:443 via SPDY |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4737 | std::unique_ptr<SpdySerializedFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4738 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4739 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4740 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4741 | const char get[] = |
| 4742 | "GET / HTTP/1.1\r\n" |
| 4743 | "Host: www.example.org\r\n" |
| 4744 | "Connection: keep-alive\r\n\r\n"; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4745 | std::unique_ptr<SpdySerializedFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4746 | spdy_util_.ConstructSpdyBodyFrame(1, get, strlen(get), false)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4747 | std::unique_ptr<SpdySerializedFrame> conn_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4748 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4749 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 4750 | "Content-Length: 10\r\n\r\n"; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4751 | std::unique_ptr<SpdySerializedFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4752 | spdy_util_.ConstructSpdyBodyFrame(1, resp, strlen(resp), false)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4753 | std::unique_ptr<SpdySerializedFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4754 | spdy_util_.ConstructSpdyBodyFrame(1, "1234567890", 10, false)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4755 | std::unique_ptr<SpdySerializedFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4756 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4757 | |
| 4758 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4759 | CreateMockWrite(*connect, 0), |
| 4760 | CreateMockWrite(*wrapped_get, 2), |
| 4761 | CreateMockWrite(*window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4762 | }; |
| 4763 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4764 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4765 | CreateMockRead(*conn_resp, 1, ASYNC), |
| 4766 | CreateMockRead(*wrapped_get_resp, 3, ASYNC), |
| 4767 | CreateMockRead(*wrapped_body, 4, ASYNC), |
| 4768 | CreateMockRead(*wrapped_body, 5, ASYNC), |
| 4769 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4770 | }; |
| 4771 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4772 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4773 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4774 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4775 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4776 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4777 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4778 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4779 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4780 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4781 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4782 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4783 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4784 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4785 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4786 | |
| 4787 | rv = callback1.WaitForResult(); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4788 | ASSERT_EQ(OK, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4789 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4790 | LoadTimingInfo load_timing_info; |
| 4791 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4792 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4793 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4794 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4795 | ASSERT_TRUE(response); |
| 4796 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4797 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4798 | |
| 4799 | std::string response_data; |
| 4800 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 4801 | EXPECT_EQ("1234567890", response_data); |
| 4802 | } |
| 4803 | |
| 4804 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4805 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4806 | SpdyTestUtil spdy_util_wrapped(GetProtocol(), GetDependenciesFromPriority()); |
| 4807 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4808 | HttpRequestInfo request; |
| 4809 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4810 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4811 | request.load_flags = 0; |
| 4812 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4813 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4814 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4815 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4816 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4817 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4818 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4819 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4820 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4821 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4822 | // CONNECT to www.example.org:443 via SPDY |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4823 | std::unique_ptr<SpdySerializedFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4824 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4825 | // fetch https://www.example.org/ via SPDY |
| 4826 | const char kMyUrl[] = "https://www.example.org/"; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4827 | std::unique_ptr<SpdySerializedFrame> get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4828 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4829 | std::unique_ptr<SpdySerializedFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4830 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4831 | std::unique_ptr<SpdySerializedFrame> conn_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4832 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4833 | std::unique_ptr<SpdySerializedFrame> get_resp( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4834 | spdy_util_wrapped.ConstructSpdyGetSynReply(NULL, 0, 1)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4835 | std::unique_ptr<SpdySerializedFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4836 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4837 | std::unique_ptr<SpdySerializedFrame> body( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 4838 | spdy_util_wrapped.ConstructSpdyBodyFrame(1, true)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4839 | std::unique_ptr<SpdySerializedFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4840 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4841 | std::unique_ptr<SpdySerializedFrame> window_update_get_resp( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4842 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4843 | std::unique_ptr<SpdySerializedFrame> window_update_body( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4844 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4845 | |
| 4846 | MockWrite spdy_writes[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4847 | CreateMockWrite(*connect, 0), |
| 4848 | CreateMockWrite(*wrapped_get, 2), |
| 4849 | CreateMockWrite(*window_update_get_resp, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4850 | CreateMockWrite(*window_update_body, 7), |
| 4851 | }; |
| 4852 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4853 | MockRead spdy_reads[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4854 | CreateMockRead(*conn_resp, 1, ASYNC), |
| 4855 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4856 | CreateMockRead(*wrapped_get_resp, 4, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4857 | CreateMockRead(*wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4858 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4859 | }; |
| 4860 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4861 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4862 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4863 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4864 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4865 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4866 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4867 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4868 | SSLSocketDataProvider ssl2(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4869 | ssl2.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4870 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4871 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4872 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4873 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4874 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4875 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4876 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4877 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 4878 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4879 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 4880 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4881 | rv = callback1.WaitForResult(); |
| 4882 | EXPECT_EQ(OK, rv); |
| 4883 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4884 | LoadTimingInfo load_timing_info; |
| 4885 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4886 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4887 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4888 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4889 | ASSERT_TRUE(response); |
| 4890 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4891 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4892 | |
| 4893 | std::string response_data; |
| 4894 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4895 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4896 | } |
| 4897 | |
| 4898 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4899 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4900 | HttpRequestInfo request; |
| 4901 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4902 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4903 | request.load_flags = 0; |
| 4904 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4905 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4906 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4907 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4908 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4909 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4910 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4911 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4912 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4913 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4914 | // CONNECT to www.example.org:443 via SPDY |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4915 | std::unique_ptr<SpdySerializedFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4916 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4917 | std::unique_ptr<SpdySerializedFrame> get( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4918 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4919 | |
| 4920 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4921 | CreateMockWrite(*connect, 0), CreateMockWrite(*get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4922 | }; |
| 4923 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4924 | std::unique_ptr<SpdySerializedFrame> resp( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 4925 | spdy_util_.ConstructSpdySynReplyError(1)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4926 | std::unique_ptr<SpdySerializedFrame> data( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 4927 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4928 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4929 | CreateMockRead(*resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4930 | }; |
| 4931 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4932 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4933 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4934 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4935 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4936 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4937 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4938 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4939 | SSLSocketDataProvider ssl2(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4940 | ssl2.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4941 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4942 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4943 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4944 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4945 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4946 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4947 | |
| 4948 | rv = callback1.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 4949 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4950 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 4951 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4952 | } |
| 4953 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4954 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 4955 | // HTTPS Proxy to different servers. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4956 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4957 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 4958 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4959 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4960 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4961 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4962 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4963 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4964 | |
| 4965 | HttpRequestInfo request1; |
| 4966 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4967 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4968 | request1.load_flags = 0; |
| 4969 | |
| 4970 | HttpRequestInfo request2; |
| 4971 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4972 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4973 | request2.load_flags = 0; |
| 4974 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4975 | // CONNECT to www.example.org:443 via SPDY. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4976 | std::unique_ptr<SpdySerializedFrame> connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4977 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4978 | std::unique_ptr<SpdySerializedFrame> conn_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4979 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4980 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4981 | // Fetch https://www.example.org/ via HTTP. |
| 4982 | const char get1[] = |
| 4983 | "GET / HTTP/1.1\r\n" |
| 4984 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4985 | "Connection: keep-alive\r\n\r\n"; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4986 | std::unique_ptr<SpdySerializedFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4987 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4988 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 4989 | "Content-Length: 1\r\n\r\n"; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4990 | std::unique_ptr<SpdySerializedFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4991 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4992 | std::unique_ptr<SpdySerializedFrame> wrapped_body1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4993 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4994 | std::unique_ptr<SpdySerializedFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4995 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4996 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4997 | // CONNECT to mail.example.org:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4998 | SpdyHeaderBlock connect2_block; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 4999 | spdy_util_.MaybeAddVersionHeader(&connect2_block); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 5000 | connect2_block[spdy_util_.GetMethodKey()] = "CONNECT"; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5001 | if (GetProtocol() == kProtoHTTP2) { |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 5002 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org:443"; |
| 5003 | } else { |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 5004 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 5005 | connect2_block[spdy_util_.GetPathKey()] = "mail.example.org:443"; |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 5006 | } |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5007 | std::unique_ptr<SpdySerializedFrame> connect2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5008 | spdy_util_.ConstructSpdySyn(3, connect2_block, LOWEST, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 5009 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5010 | std::unique_ptr<SpdySerializedFrame> conn_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5011 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5012 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5013 | // Fetch https://mail.example.org/ via HTTP. |
| 5014 | const char get2[] = |
| 5015 | "GET / HTTP/1.1\r\n" |
| 5016 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5017 | "Connection: keep-alive\r\n\r\n"; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5018 | std::unique_ptr<SpdySerializedFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5019 | spdy_util_.ConstructSpdyBodyFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5020 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5021 | "Content-Length: 2\r\n\r\n"; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5022 | std::unique_ptr<SpdySerializedFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5023 | spdy_util_.ConstructSpdyBodyFrame(3, resp2, strlen(resp2), false)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5024 | std::unique_ptr<SpdySerializedFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5025 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5026 | |
| 5027 | MockWrite spdy_writes[] = { |
| 5028 | CreateMockWrite(*connect1, 0), |
| 5029 | CreateMockWrite(*wrapped_get1, 2), |
| 5030 | CreateMockWrite(*connect2, 5), |
| 5031 | CreateMockWrite(*wrapped_get2, 7), |
| 5032 | }; |
| 5033 | |
| 5034 | MockRead spdy_reads[] = { |
| 5035 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 5036 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 5037 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 5038 | CreateMockRead(*conn_resp2, 6, ASYNC), |
| 5039 | CreateMockRead(*wrapped_get_resp2, 8, ASYNC), |
| 5040 | CreateMockRead(*wrapped_body2, 9, ASYNC), |
| 5041 | MockRead(ASYNC, 0, 10), |
| 5042 | }; |
| 5043 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5044 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5045 | arraysize(spdy_writes)); |
| 5046 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5047 | |
| 5048 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5049 | ssl.SetNextProto(GetProtocol()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5050 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5051 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5052 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5053 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5054 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5055 | |
| 5056 | TestCompletionCallback callback; |
| 5057 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5058 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5059 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5060 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5061 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5062 | |
| 5063 | LoadTimingInfo load_timing_info; |
| 5064 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5065 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5066 | |
| 5067 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5068 | ASSERT_TRUE(response); |
| 5069 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5070 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5071 | |
| 5072 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5073 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5074 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5075 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5076 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5077 | std::unique_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5078 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5079 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5080 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5081 | |
| 5082 | LoadTimingInfo load_timing_info2; |
| 5083 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5084 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 5085 | // to be created, so the socket's load timing looks like a fresh connection. |
| 5086 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5087 | |
| 5088 | // The requests should have different IDs, since they each are using their own |
| 5089 | // separate stream. |
| 5090 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5091 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5092 | rv = trans2->Read(buf.get(), 256, callback.callback()); |
| 5093 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5094 | } |
| 5095 | |
| 5096 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5097 | // HTTPS Proxy to the same server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5098 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5099 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 5100 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5101 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5102 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5103 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5104 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5105 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5106 | |
| 5107 | HttpRequestInfo request1; |
| 5108 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5109 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5110 | request1.load_flags = 0; |
| 5111 | |
| 5112 | HttpRequestInfo request2; |
| 5113 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5114 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5115 | request2.load_flags = 0; |
| 5116 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5117 | // CONNECT to www.example.org:443 via SPDY. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5118 | std::unique_ptr<SpdySerializedFrame> connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5119 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5120 | std::unique_ptr<SpdySerializedFrame> conn_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5121 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5122 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5123 | // Fetch https://www.example.org/ via HTTP. |
| 5124 | const char get1[] = |
| 5125 | "GET / HTTP/1.1\r\n" |
| 5126 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5127 | "Connection: keep-alive\r\n\r\n"; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5128 | std::unique_ptr<SpdySerializedFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5129 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5130 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5131 | "Content-Length: 1\r\n\r\n"; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5132 | std::unique_ptr<SpdySerializedFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5133 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5134 | std::unique_ptr<SpdySerializedFrame> wrapped_body1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5135 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5136 | std::unique_ptr<SpdySerializedFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 5137 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5138 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5139 | // Fetch https://www.example.org/2 via HTTP. |
| 5140 | const char get2[] = |
| 5141 | "GET /2 HTTP/1.1\r\n" |
| 5142 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5143 | "Connection: keep-alive\r\n\r\n"; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5144 | std::unique_ptr<SpdySerializedFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5145 | spdy_util_.ConstructSpdyBodyFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5146 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5147 | "Content-Length: 2\r\n\r\n"; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5148 | std::unique_ptr<SpdySerializedFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5149 | spdy_util_.ConstructSpdyBodyFrame(1, resp2, strlen(resp2), false)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5150 | std::unique_ptr<SpdySerializedFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5151 | spdy_util_.ConstructSpdyBodyFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5152 | |
| 5153 | MockWrite spdy_writes[] = { |
| 5154 | CreateMockWrite(*connect1, 0), |
| 5155 | CreateMockWrite(*wrapped_get1, 2), |
| 5156 | CreateMockWrite(*wrapped_get2, 5), |
| 5157 | }; |
| 5158 | |
| 5159 | MockRead spdy_reads[] = { |
| 5160 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 5161 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 5162 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 5163 | CreateMockRead(*wrapped_get_resp2, 6, ASYNC), |
| 5164 | CreateMockRead(*wrapped_body2, 7, ASYNC), |
| 5165 | MockRead(ASYNC, 0, 8), |
| 5166 | }; |
| 5167 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5168 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5169 | arraysize(spdy_writes)); |
| 5170 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5171 | |
| 5172 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5173 | ssl.SetNextProto(GetProtocol()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5174 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5175 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5176 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5177 | |
| 5178 | TestCompletionCallback callback; |
| 5179 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5180 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5181 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5182 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 5183 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5184 | |
| 5185 | rv = callback.WaitForResult(); |
| 5186 | EXPECT_EQ(OK, rv); |
| 5187 | |
| 5188 | LoadTimingInfo load_timing_info; |
| 5189 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5190 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5191 | |
| 5192 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5193 | ASSERT_TRUE(response); |
| 5194 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5195 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5196 | |
| 5197 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5198 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5199 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5200 | trans.reset(); |
| 5201 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5202 | std::unique_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5203 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5204 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 5205 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5206 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5207 | rv = callback.WaitForResult(); |
| 5208 | EXPECT_EQ(OK, rv); |
| 5209 | |
| 5210 | LoadTimingInfo load_timing_info2; |
| 5211 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5212 | TestLoadTimingReused(load_timing_info2); |
| 5213 | |
| 5214 | // The requests should have the same ID. |
| 5215 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5216 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5217 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5218 | } |
| 5219 | |
| 5220 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 5221 | // Proxy to different servers. |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5222 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5223 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5224 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5225 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5226 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5227 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5228 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5229 | |
| 5230 | HttpRequestInfo request1; |
| 5231 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5232 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5233 | request1.load_flags = 0; |
| 5234 | |
| 5235 | HttpRequestInfo request2; |
| 5236 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5237 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5238 | request2.load_flags = 0; |
| 5239 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5240 | // http://www.example.org/ |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5241 | std::unique_ptr<SpdyHeaderBlock> headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5242 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5243 | std::unique_ptr<SpdySerializedFrame> get1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5244 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, true)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5245 | std::unique_ptr<SpdySerializedFrame> get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5246 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5247 | std::unique_ptr<SpdySerializedFrame> body1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5248 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5249 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5250 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5251 | // http://mail.example.org/ |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5252 | std::unique_ptr<SpdyHeaderBlock> headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5253 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5254 | std::unique_ptr<SpdySerializedFrame> get2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5255 | spdy_util_.ConstructSpdySyn(3, *headers2, LOWEST, true)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5256 | std::unique_ptr<SpdySerializedFrame> get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5257 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5258 | std::unique_ptr<SpdySerializedFrame> body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5259 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5260 | |
| 5261 | MockWrite spdy_writes[] = { |
| 5262 | CreateMockWrite(*get1, 0), |
| 5263 | CreateMockWrite(*get2, 3), |
| 5264 | }; |
| 5265 | |
| 5266 | MockRead spdy_reads[] = { |
| 5267 | CreateMockRead(*get_resp1, 1, ASYNC), |
| 5268 | CreateMockRead(*body1, 2, ASYNC), |
| 5269 | CreateMockRead(*get_resp2, 4, ASYNC), |
| 5270 | CreateMockRead(*body2, 5, ASYNC), |
| 5271 | MockRead(ASYNC, 0, 6), |
| 5272 | }; |
| 5273 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5274 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5275 | arraysize(spdy_writes)); |
| 5276 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5277 | |
| 5278 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5279 | ssl.SetNextProto(GetProtocol()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5280 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5281 | |
| 5282 | TestCompletionCallback callback; |
| 5283 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5284 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5285 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5286 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5287 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5288 | |
| 5289 | LoadTimingInfo load_timing_info; |
| 5290 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5291 | TestLoadTimingNotReused(load_timing_info, |
| 5292 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5293 | |
| 5294 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5295 | ASSERT_TRUE(response); |
| 5296 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5297 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5298 | |
| 5299 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5300 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5301 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5302 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5303 | // Delete the first request, so the second one can reuse the socket. |
| 5304 | trans.reset(); |
| 5305 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5306 | std::unique_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5307 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5308 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5309 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5310 | |
| 5311 | LoadTimingInfo load_timing_info2; |
| 5312 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5313 | TestLoadTimingReused(load_timing_info2); |
| 5314 | |
| 5315 | // The requests should have the same ID. |
| 5316 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5317 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5318 | rv = trans2->Read(buf.get(), 256, callback.callback()); |
| 5319 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5320 | } |
| 5321 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5322 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5323 | TEST_P(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5324 | HttpRequestInfo request; |
| 5325 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5326 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5327 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5328 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5329 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5330 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5331 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5332 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5333 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5334 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5335 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5336 | // Since we have proxy, should use full url |
| 5337 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5338 | MockWrite( |
| 5339 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5340 | "Host: www.example.org\r\n" |
| 5341 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5342 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5343 | // After calling trans->RestartWithAuth(), this is the request we should |
| 5344 | // be issuing -- the final header line contains the credentials. |
| 5345 | MockWrite( |
| 5346 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5347 | "Host: www.example.org\r\n" |
| 5348 | "Proxy-Connection: keep-alive\r\n" |
| 5349 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5350 | }; |
| 5351 | |
| 5352 | // The proxy responds to the GET with a 407, using a persistent |
| 5353 | // connection. |
| 5354 | MockRead data_reads1[] = { |
| 5355 | // No credentials. |
| 5356 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5357 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5358 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 5359 | MockRead("Content-Length: 0\r\n\r\n"), |
| 5360 | |
| 5361 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5362 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5363 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5364 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5365 | }; |
| 5366 | |
| 5367 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5368 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5369 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5370 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5371 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5372 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5373 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5374 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5375 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5376 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5377 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5378 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5379 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5380 | |
| 5381 | rv = callback1.WaitForResult(); |
| 5382 | EXPECT_EQ(OK, rv); |
| 5383 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5384 | LoadTimingInfo load_timing_info; |
| 5385 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5386 | TestLoadTimingNotReused(load_timing_info, |
| 5387 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5388 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5389 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5390 | ASSERT_TRUE(response); |
| 5391 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5392 | EXPECT_EQ(407, response->headers->response_code()); |
| 5393 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5394 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5395 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5396 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5397 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5398 | rv = trans->RestartWithAuth( |
| 5399 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5400 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5401 | |
| 5402 | rv = callback2.WaitForResult(); |
| 5403 | EXPECT_EQ(OK, rv); |
| 5404 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5405 | load_timing_info = LoadTimingInfo(); |
| 5406 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5407 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 5408 | TestLoadTimingReused(load_timing_info); |
| 5409 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5410 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5411 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5412 | |
| 5413 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5414 | EXPECT_EQ(200, response->headers->response_code()); |
| 5415 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5416 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5417 | |
| 5418 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5419 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5420 | } |
| 5421 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5422 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5423 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5424 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5425 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5426 | request.url = GURL("https://www.example.org/"); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5427 | request.load_flags = 0; |
| 5428 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5429 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5430 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5431 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5432 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5433 | // Since we have proxy, should try to establish tunnel. |
| 5434 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5435 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5436 | "Host: www.example.org:443\r\n" |
| 5437 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5438 | }; |
| 5439 | |
| 5440 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 5441 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 5442 | // No response body because the test stops reading here. |
| 5443 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5444 | }; |
| 5445 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5446 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5447 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5448 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5449 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5450 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5451 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5452 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5453 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5454 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5455 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5456 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5457 | |
| 5458 | rv = callback.WaitForResult(); |
| 5459 | EXPECT_EQ(expected_status, rv); |
| 5460 | } |
| 5461 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5462 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5463 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5464 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5465 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5466 | } |
| 5467 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5468 | TEST_P(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5469 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 5470 | } |
| 5471 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5472 | TEST_P(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5473 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 5474 | } |
| 5475 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5476 | TEST_P(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5477 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 5478 | } |
| 5479 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5480 | TEST_P(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5481 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 5482 | } |
| 5483 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5484 | TEST_P(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5485 | ConnectStatusHelper( |
| 5486 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 5487 | } |
| 5488 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5489 | TEST_P(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5490 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 5491 | } |
| 5492 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5493 | TEST_P(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5494 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 5495 | } |
| 5496 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5497 | TEST_P(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5498 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 5499 | } |
| 5500 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5501 | TEST_P(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5502 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 5503 | } |
| 5504 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5505 | TEST_P(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5506 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 5507 | } |
| 5508 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5509 | TEST_P(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5510 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 5511 | } |
| 5512 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5513 | TEST_P(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5514 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 5515 | } |
| 5516 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5517 | TEST_P(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5518 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 5519 | } |
| 5520 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5521 | TEST_P(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5522 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 5523 | } |
| 5524 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5525 | TEST_P(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5526 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 5527 | } |
| 5528 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5529 | TEST_P(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5530 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 5531 | } |
| 5532 | |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 5533 | TEST_P(HttpNetworkTransactionTest, ConnectStatus308) { |
| 5534 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 5535 | } |
| 5536 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5537 | TEST_P(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5538 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 5539 | } |
| 5540 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5541 | TEST_P(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5542 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 5543 | } |
| 5544 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5545 | TEST_P(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5546 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 5547 | } |
| 5548 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5549 | TEST_P(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5550 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 5551 | } |
| 5552 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5553 | TEST_P(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5554 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 5555 | } |
| 5556 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5557 | TEST_P(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5558 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 5559 | } |
| 5560 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5561 | TEST_P(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5562 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 5563 | } |
| 5564 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5565 | TEST_P(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5566 | ConnectStatusHelperWithExpectedStatus( |
| 5567 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 5568 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5569 | } |
| 5570 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5571 | TEST_P(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5572 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 5573 | } |
| 5574 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5575 | TEST_P(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5576 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 5577 | } |
| 5578 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5579 | TEST_P(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5580 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 5581 | } |
| 5582 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5583 | TEST_P(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5584 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 5585 | } |
| 5586 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5587 | TEST_P(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5588 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 5589 | } |
| 5590 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5591 | TEST_P(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5592 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 5593 | } |
| 5594 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5595 | TEST_P(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5596 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 5597 | } |
| 5598 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5599 | TEST_P(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5600 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 5601 | } |
| 5602 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5603 | TEST_P(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5604 | ConnectStatusHelper( |
| 5605 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 5606 | } |
| 5607 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5608 | TEST_P(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5609 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 5610 | } |
| 5611 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5612 | TEST_P(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5613 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 5614 | } |
| 5615 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5616 | TEST_P(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5617 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 5618 | } |
| 5619 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5620 | TEST_P(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5621 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 5622 | } |
| 5623 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5624 | TEST_P(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5625 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 5626 | } |
| 5627 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5628 | TEST_P(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5629 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 5630 | } |
| 5631 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5632 | TEST_P(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5633 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 5634 | } |
| 5635 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5636 | // Test the flow when both the proxy server AND origin server require |
| 5637 | // authentication. Again, this uses basic auth for both since that is |
| 5638 | // the simplest to mock. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5639 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5640 | HttpRequestInfo request; |
| 5641 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5642 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5643 | request.load_flags = 0; |
| 5644 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5645 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5646 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5647 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5648 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5649 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5650 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5651 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5652 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5653 | MockWrite( |
| 5654 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5655 | "Host: www.example.org\r\n" |
| 5656 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5657 | }; |
| 5658 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5659 | MockRead data_reads1[] = { |
| 5660 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 5661 | // Give a couple authenticate options (only the middle one is actually |
| 5662 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 5663 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5664 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5665 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 5666 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5667 | // Large content-length -- won't matter, as connection will be reset. |
| 5668 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5669 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5670 | }; |
| 5671 | |
| 5672 | // After calling trans->RestartWithAuth() the first time, this is the |
| 5673 | // request we should be issuing -- the final header line contains the |
| 5674 | // proxy's credentials. |
| 5675 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5676 | MockWrite( |
| 5677 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5678 | "Host: www.example.org\r\n" |
| 5679 | "Proxy-Connection: keep-alive\r\n" |
| 5680 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5681 | }; |
| 5682 | |
| 5683 | // Now the proxy server lets the request pass through to origin server. |
| 5684 | // The origin server responds with a 401. |
| 5685 | MockRead data_reads2[] = { |
| 5686 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5687 | // Note: We are using the same realm-name as the proxy server. This is |
| 5688 | // completely valid, as realms are unique across hosts. |
| 5689 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5690 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5691 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5692 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5693 | }; |
| 5694 | |
| 5695 | // After calling trans->RestartWithAuth() the second time, we should send |
| 5696 | // the credentials for both the proxy and origin server. |
| 5697 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5698 | MockWrite( |
| 5699 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5700 | "Host: www.example.org\r\n" |
| 5701 | "Proxy-Connection: keep-alive\r\n" |
| 5702 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 5703 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5704 | }; |
| 5705 | |
| 5706 | // Lastly we get the desired content. |
| 5707 | MockRead data_reads3[] = { |
| 5708 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5709 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5710 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5711 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5712 | }; |
| 5713 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5714 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5715 | data_writes1, arraysize(data_writes1)); |
| 5716 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5717 | data_writes2, arraysize(data_writes2)); |
| 5718 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5719 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5720 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5721 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5722 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5723 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5724 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5725 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5726 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5727 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5728 | |
| 5729 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5730 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5731 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5732 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5733 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5734 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5735 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5736 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5737 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5738 | rv = trans->RestartWithAuth( |
| 5739 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5740 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5741 | |
| 5742 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5743 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5744 | |
| 5745 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5746 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5747 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5748 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5749 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5750 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5751 | rv = trans->RestartWithAuth( |
| 5752 | AuthCredentials(kFoo2, kBar2), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5753 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5754 | |
| 5755 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5756 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5757 | |
| 5758 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5759 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5760 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5761 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5762 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5763 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 5764 | // can't hook into its internals to cause it to generate predictable NTLM |
| 5765 | // authorization headers. |
| 5766 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5767 | // The NTLM authentication unit tests were generated by capturing the HTTP |
| 5768 | // requests and responses using Fiddler 2 and inspecting the generated random |
| 5769 | // bytes in the debugger. |
| 5770 | |
| 5771 | // Enter the correct password and authenticate successfully. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5772 | TEST_P(HttpNetworkTransactionTest, NTLMAuth1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5773 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5774 | request.method = "GET"; |
| 5775 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5776 | |
| 5777 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 5778 | // to other auth schemes. |
| 5779 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5780 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5781 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 5782 | MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5783 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5784 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5785 | MockWrite data_writes1[] = { |
| 5786 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5787 | "Host: 172.22.68.17\r\n" |
| 5788 | "Connection: keep-alive\r\n\r\n"), |
| 5789 | }; |
| 5790 | |
| 5791 | MockRead data_reads1[] = { |
| 5792 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 5793 | // Negotiate and NTLM are often requested together. However, we only want |
| 5794 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 5795 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5796 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5797 | MockRead("Connection: close\r\n"), |
| 5798 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5799 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5800 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5801 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5802 | }; |
| 5803 | |
| 5804 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5805 | // After restarting with a null identity, this is the |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5806 | // request we should be issuing -- the final header line contains a Type |
| 5807 | // 1 message. |
| 5808 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5809 | "Host: 172.22.68.17\r\n" |
| 5810 | "Connection: keep-alive\r\n" |
| 5811 | "Authorization: NTLM " |
| 5812 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 5813 | |
| 5814 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 5815 | // (the credentials for the origin server). The second request continues |
| 5816 | // on the same connection. |
| 5817 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5818 | "Host: 172.22.68.17\r\n" |
| 5819 | "Connection: keep-alive\r\n" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5820 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5821 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5822 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 5823 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 5824 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5825 | }; |
| 5826 | |
| 5827 | MockRead data_reads2[] = { |
| 5828 | // The origin server responds with a Type 2 message. |
| 5829 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5830 | MockRead("WWW-Authenticate: NTLM " |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5831 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5832 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5833 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5834 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5835 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5836 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5837 | "BtAAAAAAA=\r\n"), |
| 5838 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5839 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5840 | MockRead("You are not authorized to view this page\r\n"), |
| 5841 | |
| 5842 | // Lastly we get the desired content. |
| 5843 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5844 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 5845 | MockRead("Content-Length: 13\r\n\r\n"), |
| 5846 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5847 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5848 | }; |
| 5849 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5850 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5851 | data_writes1, arraysize(data_writes1)); |
| 5852 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5853 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5854 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5855 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5856 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5857 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5858 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5859 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5860 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5861 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5862 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5863 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5864 | |
| 5865 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5866 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5867 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5868 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5869 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5870 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5871 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5872 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5873 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5874 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5875 | |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5876 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5877 | callback2.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5878 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5879 | |
| 5880 | rv = callback2.WaitForResult(); |
| 5881 | EXPECT_EQ(OK, rv); |
| 5882 | |
| 5883 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5884 | |
| 5885 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5886 | ASSERT_TRUE(response); |
| 5887 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5888 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5889 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5890 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5891 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5892 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5893 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5894 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5895 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5896 | |
| 5897 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5898 | ASSERT_TRUE(response); |
| 5899 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5900 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 5901 | } |
| 5902 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5903 | // Enter a wrong password, and then the correct one. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5904 | TEST_P(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5905 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5906 | request.method = "GET"; |
| 5907 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 5908 | request.load_flags = 0; |
| 5909 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5910 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 5911 | MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5912 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5913 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5914 | MockWrite data_writes1[] = { |
| 5915 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5916 | "Host: 172.22.68.17\r\n" |
| 5917 | "Connection: keep-alive\r\n\r\n"), |
| 5918 | }; |
| 5919 | |
| 5920 | MockRead data_reads1[] = { |
| 5921 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 5922 | // Negotiate and NTLM are often requested together. However, we only want |
| 5923 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 5924 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5925 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5926 | MockRead("Connection: close\r\n"), |
| 5927 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5928 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5929 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5930 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5931 | }; |
| 5932 | |
| 5933 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5934 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5935 | // request we should be issuing -- the final header line contains a Type |
| 5936 | // 1 message. |
| 5937 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5938 | "Host: 172.22.68.17\r\n" |
| 5939 | "Connection: keep-alive\r\n" |
| 5940 | "Authorization: NTLM " |
| 5941 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 5942 | |
| 5943 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 5944 | // (the credentials for the origin server). The second request continues |
| 5945 | // on the same connection. |
| 5946 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5947 | "Host: 172.22.68.17\r\n" |
| 5948 | "Connection: keep-alive\r\n" |
| 5949 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5950 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5951 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 5952 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 5953 | "4Ww7b7E=\r\n\r\n"), |
| 5954 | }; |
| 5955 | |
| 5956 | MockRead data_reads2[] = { |
| 5957 | // The origin server responds with a Type 2 message. |
| 5958 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5959 | MockRead("WWW-Authenticate: NTLM " |
| 5960 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 5961 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5962 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5963 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5964 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5965 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5966 | "BtAAAAAAA=\r\n"), |
| 5967 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5968 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5969 | MockRead("You are not authorized to view this page\r\n"), |
| 5970 | |
| 5971 | // Wrong password. |
| 5972 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5973 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5974 | MockRead("Connection: close\r\n"), |
| 5975 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5976 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5977 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5978 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5979 | }; |
| 5980 | |
| 5981 | MockWrite data_writes3[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5982 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5983 | // request we should be issuing -- the final header line contains a Type |
| 5984 | // 1 message. |
| 5985 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5986 | "Host: 172.22.68.17\r\n" |
| 5987 | "Connection: keep-alive\r\n" |
| 5988 | "Authorization: NTLM " |
| 5989 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 5990 | |
| 5991 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 5992 | // (the credentials for the origin server). The second request continues |
| 5993 | // on the same connection. |
| 5994 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5995 | "Host: 172.22.68.17\r\n" |
| 5996 | "Connection: keep-alive\r\n" |
| 5997 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5998 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5999 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 6000 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 6001 | "+4MUm7c=\r\n\r\n"), |
| 6002 | }; |
| 6003 | |
| 6004 | MockRead data_reads3[] = { |
| 6005 | // The origin server responds with a Type 2 message. |
| 6006 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6007 | MockRead("WWW-Authenticate: NTLM " |
| 6008 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 6009 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 6010 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 6011 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 6012 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 6013 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 6014 | "BtAAAAAAA=\r\n"), |
| 6015 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6016 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6017 | MockRead("You are not authorized to view this page\r\n"), |
| 6018 | |
| 6019 | // Lastly we get the desired content. |
| 6020 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6021 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6022 | MockRead("Content-Length: 13\r\n\r\n"), |
| 6023 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6024 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6025 | }; |
| 6026 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6027 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6028 | data_writes1, arraysize(data_writes1)); |
| 6029 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6030 | data_writes2, arraysize(data_writes2)); |
| 6031 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6032 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6033 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6034 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6035 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6036 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6037 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6038 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6039 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6040 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6041 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6042 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6043 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6044 | |
| 6045 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6046 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6047 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6048 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6049 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6050 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6051 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6052 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6053 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6054 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6055 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6056 | // Enter the wrong password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 6057 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6058 | callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6059 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6060 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6061 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6062 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6063 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6064 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6065 | TestCompletionCallback callback3; |
| 6066 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6067 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6068 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6069 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6070 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6071 | |
| 6072 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6073 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6074 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6075 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6076 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6077 | |
| 6078 | // Now enter the right password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 6079 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6080 | callback4.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6081 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6082 | |
| 6083 | rv = callback4.WaitForResult(); |
| 6084 | EXPECT_EQ(OK, rv); |
| 6085 | |
| 6086 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 6087 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6088 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6089 | |
| 6090 | // One more roundtrip |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6091 | rv = trans->RestartWithAuth(AuthCredentials(), callback5.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6092 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6093 | |
| 6094 | rv = callback5.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6095 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6096 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6097 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6098 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6099 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 6100 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6101 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6102 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6103 | // Test reading a server response which has only headers, and no body. |
| 6104 | // After some maximum number of bytes is consumed, the transaction should |
| 6105 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6106 | TEST_P(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6107 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6108 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6109 | request.url = GURL("http://www.example.org/"); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6110 | request.load_flags = 0; |
| 6111 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6112 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6113 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6114 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6115 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6116 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 6117 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6118 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6119 | |
| 6120 | MockRead data_reads[] = { |
| 6121 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6122 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6123 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6124 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6125 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6126 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6127 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6128 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6129 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6130 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6131 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6132 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6133 | |
| 6134 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6135 | EXPECT_EQ(ERR_RESPONSE_HEADERS_TOO_BIG, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6136 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6137 | |
| 6138 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 6139 | // establish tunnel. |
| 6140 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6141 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 6142 | DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6143 | HttpRequestInfo request; |
| 6144 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6145 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6146 | request.load_flags = 0; |
| 6147 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6148 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 6149 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 6150 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6151 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6152 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6153 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6154 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6155 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6156 | // Since we have proxy, should try to establish tunnel. |
| 6157 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6158 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6159 | "Host: www.example.org:443\r\n" |
| 6160 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6161 | }; |
| 6162 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 6163 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6164 | // connection. Usually a proxy would return 501 (not implemented), |
| 6165 | // or 200 (tunnel established). |
| 6166 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6167 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 6168 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6169 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6170 | }; |
| 6171 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6172 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6173 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6174 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6175 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6176 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6177 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6178 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6179 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6180 | |
| 6181 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6182 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6183 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6184 | // Empty the current queue. This is necessary because idle sockets are |
| 6185 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6186 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6187 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6188 | // We now check to make sure the TCPClientSocket was not added back to |
| 6189 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6190 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6191 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6192 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6193 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6194 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6195 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6196 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6197 | // 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] | 6198 | TEST_P(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6199 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6200 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6201 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6202 | request.load_flags = 0; |
| 6203 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6204 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6205 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6206 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6207 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6208 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6209 | MockRead data_reads[] = { |
| 6210 | // A part of the response body is received with the response headers. |
| 6211 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 6212 | // The rest of the response body is received in two parts. |
| 6213 | MockRead("lo"), |
| 6214 | MockRead(" world"), |
| 6215 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6216 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6217 | }; |
| 6218 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6219 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6220 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6221 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6222 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6223 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6224 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6225 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6226 | |
| 6227 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6228 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6229 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6230 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6231 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6232 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6233 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6234 | std::string status_line = response->headers->GetStatusLine(); |
| 6235 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 6236 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6237 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6238 | |
| 6239 | std::string response_data; |
| 6240 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6241 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6242 | EXPECT_EQ("hello world", response_data); |
| 6243 | |
| 6244 | // Empty the current queue. This is necessary because idle sockets are |
| 6245 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6246 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6247 | |
| 6248 | // 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] | 6249 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6250 | } |
| 6251 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6252 | // Make sure that we recycle a SSL socket after reading all of the response |
| 6253 | // body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6254 | TEST_P(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6255 | HttpRequestInfo request; |
| 6256 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6257 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6258 | request.load_flags = 0; |
| 6259 | |
| 6260 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6261 | MockWrite( |
| 6262 | "GET / HTTP/1.1\r\n" |
| 6263 | "Host: www.example.org\r\n" |
| 6264 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6265 | }; |
| 6266 | |
| 6267 | MockRead data_reads[] = { |
| 6268 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6269 | MockRead("Content-Length: 11\r\n\r\n"), |
| 6270 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6271 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6272 | }; |
| 6273 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6274 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6275 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6276 | |
| 6277 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6278 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6279 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6280 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6281 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6282 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6283 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6284 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6285 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6286 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6287 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6288 | |
| 6289 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6290 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 6291 | |
| 6292 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6293 | ASSERT_TRUE(response); |
| 6294 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6295 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6296 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6297 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6298 | |
| 6299 | std::string response_data; |
| 6300 | rv = ReadTransaction(trans.get(), &response_data); |
| 6301 | EXPECT_EQ(OK, rv); |
| 6302 | EXPECT_EQ("hello world", response_data); |
| 6303 | |
| 6304 | // Empty the current queue. This is necessary because idle sockets are |
| 6305 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6306 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6307 | |
| 6308 | // 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] | 6309 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6310 | } |
| 6311 | |
| 6312 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 6313 | // from the pool and make sure that we recover okay. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6314 | TEST_P(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6315 | HttpRequestInfo request; |
| 6316 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6317 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6318 | request.load_flags = 0; |
| 6319 | |
| 6320 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6321 | MockWrite( |
| 6322 | "GET / HTTP/1.1\r\n" |
| 6323 | "Host: www.example.org\r\n" |
| 6324 | "Connection: keep-alive\r\n\r\n"), |
| 6325 | MockWrite( |
| 6326 | "GET / HTTP/1.1\r\n" |
| 6327 | "Host: www.example.org\r\n" |
| 6328 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6329 | }; |
| 6330 | |
| 6331 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 6332 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6333 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6334 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6335 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6336 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6337 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6338 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6339 | |
| 6340 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6341 | data_writes, arraysize(data_writes)); |
| 6342 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 6343 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6344 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6345 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6346 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6347 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6348 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6349 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6350 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6351 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6352 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6353 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6354 | |
| 6355 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6356 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 6357 | |
| 6358 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6359 | ASSERT_TRUE(response); |
| 6360 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6361 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6362 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6363 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6364 | |
| 6365 | std::string response_data; |
| 6366 | rv = ReadTransaction(trans.get(), &response_data); |
| 6367 | EXPECT_EQ(OK, rv); |
| 6368 | EXPECT_EQ("hello world", response_data); |
| 6369 | |
| 6370 | // Empty the current queue. This is necessary because idle sockets are |
| 6371 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6372 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6373 | |
| 6374 | // 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] | 6375 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6376 | |
| 6377 | // Now start the second transaction, which should reuse the previous socket. |
| 6378 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6379 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6380 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6381 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6382 | |
| 6383 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6384 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 6385 | |
| 6386 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6387 | ASSERT_TRUE(response); |
| 6388 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6389 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6390 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6391 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6392 | |
| 6393 | rv = ReadTransaction(trans.get(), &response_data); |
| 6394 | EXPECT_EQ(OK, rv); |
| 6395 | EXPECT_EQ("hello world", response_data); |
| 6396 | |
| 6397 | // Empty the current queue. This is necessary because idle sockets are |
| 6398 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6399 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6400 | |
| 6401 | // 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] | 6402 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6403 | } |
| 6404 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6405 | // Make sure that we recycle a socket after a zero-length response. |
| 6406 | // http://crbug.com/9880 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6407 | TEST_P(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6408 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6409 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6410 | request.url = GURL( |
| 6411 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 6412 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 6413 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 6414 | "rt=prt.2642,ol.2649,xjs.2951"); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6415 | request.load_flags = 0; |
| 6416 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6417 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6418 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6419 | MockRead data_reads[] = { |
| 6420 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 6421 | "Content-Length: 0\r\n" |
| 6422 | "Content-Type: text/html\r\n\r\n"), |
| 6423 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6424 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6425 | }; |
| 6426 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6427 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6428 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6429 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 6430 | // Transaction must be created after the MockReads, so it's destroyed before |
| 6431 | // them. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6432 | std::unique_ptr<HttpTransaction> trans( |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 6433 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 6434 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6435 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6436 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6437 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6438 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6439 | |
| 6440 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6441 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6442 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6443 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6444 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6445 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6446 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6447 | std::string status_line = response->headers->GetStatusLine(); |
| 6448 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 6449 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6450 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6451 | |
| 6452 | std::string response_data; |
| 6453 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6454 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6455 | EXPECT_EQ("", response_data); |
| 6456 | |
| 6457 | // Empty the current queue. This is necessary because idle sockets are |
| 6458 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6459 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6460 | |
| 6461 | // 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] | 6462 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6463 | } |
| 6464 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6465 | TEST_P(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6466 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6467 | element_readers.push_back( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6468 | base::WrapUnique(new UploadBytesElementReader("foo", 3))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6469 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6470 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6471 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6472 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 6473 | // after use. |
| 6474 | request[0].method = "GET"; |
| 6475 | request[0].url = GURL("http://www.google.com/"); |
| 6476 | request[0].load_flags = 0; |
| 6477 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 6478 | // transaction 1. The first attempts fails when writing the POST data. |
| 6479 | // This causes the transaction to retry with a new socket. The second |
| 6480 | // attempt succeeds. |
| 6481 | request[1].method = "POST"; |
| 6482 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6483 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6484 | request[1].load_flags = 0; |
| 6485 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6486 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6487 | |
| 6488 | // The first socket is used for transaction 1 and the first attempt of |
| 6489 | // transaction 2. |
| 6490 | |
| 6491 | // The response of transaction 1. |
| 6492 | MockRead data_reads1[] = { |
| 6493 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 6494 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6495 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6496 | }; |
| 6497 | // The mock write results of transaction 1 and the first attempt of |
| 6498 | // transaction 2. |
| 6499 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6500 | MockWrite(SYNCHRONOUS, 64), // GET |
| 6501 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6502 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6503 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6504 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6505 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6506 | |
| 6507 | // The second socket is used for the second attempt of transaction 2. |
| 6508 | |
| 6509 | // The response of transaction 2. |
| 6510 | MockRead data_reads2[] = { |
| 6511 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 6512 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6513 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6514 | }; |
| 6515 | // The mock write results of the second attempt of transaction 2. |
| 6516 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6517 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6518 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6519 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6520 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6521 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6522 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6523 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6524 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6525 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 6526 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6527 | "hello world", "welcome" |
| 6528 | }; |
| 6529 | |
| 6530 | for (int i = 0; i < 2; ++i) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6531 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6532 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6533 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6534 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6535 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6536 | int rv = trans->Start(&request[i], callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6537 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6538 | |
| 6539 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6540 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6541 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6542 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6543 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6544 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6545 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6546 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6547 | |
| 6548 | std::string response_data; |
| 6549 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6550 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6551 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 6552 | } |
| 6553 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6554 | |
| 6555 | // Test the request-challenge-retry sequence for basic auth when there is |
| 6556 | // 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] | 6557 | // it fails the identity from the URL is used to answer the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6558 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6559 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6560 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6561 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 6562 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6563 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6564 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6565 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6566 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6567 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6568 | // The password contains an escaped character -- for this test to pass it |
| 6569 | // will need to be unescaped by HttpNetworkTransaction. |
| 6570 | EXPECT_EQ("b%40r", request.url.password()); |
| 6571 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6572 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6573 | MockWrite( |
| 6574 | "GET / HTTP/1.1\r\n" |
| 6575 | "Host: www.example.org\r\n" |
| 6576 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6577 | }; |
| 6578 | |
| 6579 | MockRead data_reads1[] = { |
| 6580 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6581 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6582 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6583 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6584 | }; |
| 6585 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6586 | // After the challenge above, the transaction will be restarted using the |
| 6587 | // identity from the url (foo, b@r) to answer the challenge. |
| 6588 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6589 | MockWrite( |
| 6590 | "GET / HTTP/1.1\r\n" |
| 6591 | "Host: www.example.org\r\n" |
| 6592 | "Connection: keep-alive\r\n" |
| 6593 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6594 | }; |
| 6595 | |
| 6596 | MockRead data_reads2[] = { |
| 6597 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6598 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6599 | MockRead(SYNCHRONOUS, OK), |
| 6600 | }; |
| 6601 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6602 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6603 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6604 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6605 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6606 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6607 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6608 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6609 | TestCompletionCallback callback1; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6610 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6611 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6612 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6613 | EXPECT_EQ(OK, rv); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6614 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 6615 | |
| 6616 | TestCompletionCallback callback2; |
| 6617 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 6618 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6619 | rv = callback2.WaitForResult(); |
| 6620 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6621 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6622 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6623 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6624 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6625 | |
| 6626 | // There is no challenge info, since the identity in URL worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6627 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6628 | |
| 6629 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6630 | |
| 6631 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6632 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6633 | } |
| 6634 | |
| 6635 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 6636 | // incorrect identity in the URL. The identity from the URL should be used only |
| 6637 | // once. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6638 | TEST_P(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6639 | HttpRequestInfo request; |
| 6640 | request.method = "GET"; |
| 6641 | // Note: the URL has a username:password in it. The password "baz" is |
| 6642 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6643 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6644 | |
| 6645 | request.load_flags = LOAD_NORMAL; |
| 6646 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6647 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6648 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6649 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6650 | |
| 6651 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6652 | MockWrite( |
| 6653 | "GET / HTTP/1.1\r\n" |
| 6654 | "Host: www.example.org\r\n" |
| 6655 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6656 | }; |
| 6657 | |
| 6658 | MockRead data_reads1[] = { |
| 6659 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6660 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6661 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6662 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6663 | }; |
| 6664 | |
| 6665 | // After the challenge above, the transaction will be restarted using the |
| 6666 | // identity from the url (foo, baz) to answer the challenge. |
| 6667 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6668 | MockWrite( |
| 6669 | "GET / HTTP/1.1\r\n" |
| 6670 | "Host: www.example.org\r\n" |
| 6671 | "Connection: keep-alive\r\n" |
| 6672 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6673 | }; |
| 6674 | |
| 6675 | MockRead data_reads2[] = { |
| 6676 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6677 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6678 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6679 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6680 | }; |
| 6681 | |
| 6682 | // After the challenge above, the transaction will be restarted using the |
| 6683 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 6684 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6685 | MockWrite( |
| 6686 | "GET / HTTP/1.1\r\n" |
| 6687 | "Host: www.example.org\r\n" |
| 6688 | "Connection: keep-alive\r\n" |
| 6689 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6690 | }; |
| 6691 | |
| 6692 | MockRead data_reads3[] = { |
| 6693 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6694 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6695 | MockRead(SYNCHRONOUS, OK), |
| 6696 | }; |
| 6697 | |
| 6698 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6699 | data_writes1, arraysize(data_writes1)); |
| 6700 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6701 | data_writes2, arraysize(data_writes2)); |
| 6702 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6703 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6704 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6705 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6706 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6707 | |
| 6708 | TestCompletionCallback callback1; |
| 6709 | |
| 6710 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 6711 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6712 | |
| 6713 | rv = callback1.WaitForResult(); |
| 6714 | EXPECT_EQ(OK, rv); |
| 6715 | |
| 6716 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 6717 | TestCompletionCallback callback2; |
| 6718 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 6719 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6720 | rv = callback2.WaitForResult(); |
| 6721 | EXPECT_EQ(OK, rv); |
| 6722 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6723 | |
| 6724 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6725 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6726 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 6727 | |
| 6728 | TestCompletionCallback callback3; |
| 6729 | rv = trans->RestartWithAuth( |
| 6730 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 6731 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6732 | rv = callback3.WaitForResult(); |
| 6733 | EXPECT_EQ(OK, rv); |
| 6734 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6735 | |
| 6736 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6737 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6738 | |
| 6739 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6740 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6741 | |
| 6742 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6743 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6744 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6745 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6746 | } |
| 6747 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6748 | |
| 6749 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 6750 | // correct identity in the URL, but its use is being suppressed. The identity |
| 6751 | // from the URL should never be used. |
| 6752 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
| 6753 | HttpRequestInfo request; |
| 6754 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6755 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6756 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 6757 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6758 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6759 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6760 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6761 | |
| 6762 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6763 | MockWrite( |
| 6764 | "GET / HTTP/1.1\r\n" |
| 6765 | "Host: www.example.org\r\n" |
| 6766 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6767 | }; |
| 6768 | |
| 6769 | MockRead data_reads1[] = { |
| 6770 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6771 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6772 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6773 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6774 | }; |
| 6775 | |
| 6776 | // After the challenge above, the transaction will be restarted using the |
| 6777 | // identity supplied by the user, not the one in the URL, to answer the |
| 6778 | // challenge. |
| 6779 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6780 | MockWrite( |
| 6781 | "GET / HTTP/1.1\r\n" |
| 6782 | "Host: www.example.org\r\n" |
| 6783 | "Connection: keep-alive\r\n" |
| 6784 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6785 | }; |
| 6786 | |
| 6787 | MockRead data_reads3[] = { |
| 6788 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6789 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6790 | MockRead(SYNCHRONOUS, OK), |
| 6791 | }; |
| 6792 | |
| 6793 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6794 | data_writes1, arraysize(data_writes1)); |
| 6795 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6796 | data_writes3, arraysize(data_writes3)); |
| 6797 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6798 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 6799 | |
| 6800 | TestCompletionCallback callback1; |
| 6801 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 6802 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6803 | rv = callback1.WaitForResult(); |
| 6804 | EXPECT_EQ(OK, rv); |
| 6805 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6806 | |
| 6807 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6808 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6809 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 6810 | |
| 6811 | TestCompletionCallback callback3; |
| 6812 | rv = trans->RestartWithAuth( |
| 6813 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 6814 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6815 | rv = callback3.WaitForResult(); |
| 6816 | EXPECT_EQ(OK, rv); |
| 6817 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6818 | |
| 6819 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6820 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6821 | |
| 6822 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6823 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6824 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6825 | |
| 6826 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6827 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6828 | } |
| 6829 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6830 | // Test that previously tried username/passwords for a realm get re-used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6831 | TEST_P(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6832 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6833 | |
| 6834 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 6835 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6836 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6837 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6838 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6839 | request.load_flags = 0; |
| 6840 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6841 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6842 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6843 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6844 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6845 | MockWrite( |
| 6846 | "GET /x/y/z HTTP/1.1\r\n" |
| 6847 | "Host: www.example.org\r\n" |
| 6848 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6849 | }; |
| 6850 | |
| 6851 | MockRead data_reads1[] = { |
| 6852 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6853 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6854 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6855 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6856 | }; |
| 6857 | |
| 6858 | // Resend with authorization (username=foo, password=bar) |
| 6859 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6860 | MockWrite( |
| 6861 | "GET /x/y/z HTTP/1.1\r\n" |
| 6862 | "Host: www.example.org\r\n" |
| 6863 | "Connection: keep-alive\r\n" |
| 6864 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6865 | }; |
| 6866 | |
| 6867 | // Sever accepts the authorization. |
| 6868 | MockRead data_reads2[] = { |
| 6869 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6870 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6871 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6872 | }; |
| 6873 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6874 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6875 | data_writes1, arraysize(data_writes1)); |
| 6876 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6877 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6878 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6879 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6880 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6881 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6882 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6883 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6884 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6885 | |
| 6886 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6887 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6888 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6889 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6890 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6891 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6892 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6893 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6894 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6895 | rv = trans->RestartWithAuth( |
| 6896 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6897 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6898 | |
| 6899 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6900 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6901 | |
| 6902 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6903 | ASSERT_TRUE(response); |
| 6904 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6905 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6906 | } |
| 6907 | |
| 6908 | // ------------------------------------------------------------------------ |
| 6909 | |
| 6910 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 6911 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6912 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6913 | request.method = "GET"; |
| 6914 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 6915 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6916 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6917 | request.load_flags = 0; |
| 6918 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6919 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6920 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6921 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6922 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6923 | MockWrite( |
| 6924 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 6925 | "Host: www.example.org\r\n" |
| 6926 | "Connection: keep-alive\r\n" |
| 6927 | // Send preemptive authorization for MyRealm1 |
| 6928 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6929 | }; |
| 6930 | |
| 6931 | // The server didn't like the preemptive authorization, and |
| 6932 | // challenges us for a different realm (MyRealm2). |
| 6933 | MockRead data_reads1[] = { |
| 6934 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6935 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 6936 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6937 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6938 | }; |
| 6939 | |
| 6940 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 6941 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6942 | MockWrite( |
| 6943 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 6944 | "Host: www.example.org\r\n" |
| 6945 | "Connection: keep-alive\r\n" |
| 6946 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6947 | }; |
| 6948 | |
| 6949 | // Sever accepts the authorization. |
| 6950 | MockRead data_reads2[] = { |
| 6951 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6952 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6953 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6954 | }; |
| 6955 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6956 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6957 | data_writes1, arraysize(data_writes1)); |
| 6958 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6959 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6960 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6961 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6962 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6963 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6964 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6965 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6966 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6967 | |
| 6968 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6969 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6970 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6971 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6972 | ASSERT_TRUE(response); |
| 6973 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6974 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6975 | EXPECT_EQ("www.example.org:80", |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6976 | response->auth_challenge->challenger.ToString()); |
| 6977 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 6978 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6979 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6980 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6981 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6982 | rv = trans->RestartWithAuth( |
| 6983 | AuthCredentials(kFoo2, kBar2), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6984 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6985 | |
| 6986 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6987 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6988 | |
| 6989 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6990 | ASSERT_TRUE(response); |
| 6991 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6992 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6993 | } |
| 6994 | |
| 6995 | // ------------------------------------------------------------------------ |
| 6996 | |
| 6997 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 6998 | // succeed with preemptive authorization. |
| 6999 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7000 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7001 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7002 | request.url = GURL("http://www.example.org/x/y/z2"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7003 | request.load_flags = 0; |
| 7004 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7005 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7006 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7007 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7008 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7009 | MockWrite( |
| 7010 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 7011 | "Host: www.example.org\r\n" |
| 7012 | "Connection: keep-alive\r\n" |
| 7013 | // The authorization for MyRealm1 gets sent preemptively |
| 7014 | // (since the url is in the same protection space) |
| 7015 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7016 | }; |
| 7017 | |
| 7018 | // Sever accepts the preemptive authorization |
| 7019 | MockRead data_reads1[] = { |
| 7020 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7021 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7022 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7023 | }; |
| 7024 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7025 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7026 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7027 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7028 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7029 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7030 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7031 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7032 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7033 | |
| 7034 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7035 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7036 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7037 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7038 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7039 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7040 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7041 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7042 | } |
| 7043 | |
| 7044 | // ------------------------------------------------------------------------ |
| 7045 | |
| 7046 | // Transaction 4: request another URL in MyRealm (however the |
| 7047 | // url is not known to belong to the protection space, so no pre-auth). |
| 7048 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7049 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7050 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7051 | request.url = GURL("http://www.example.org/x/1"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7052 | request.load_flags = 0; |
| 7053 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7054 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7055 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7056 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7057 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7058 | MockWrite( |
| 7059 | "GET /x/1 HTTP/1.1\r\n" |
| 7060 | "Host: www.example.org\r\n" |
| 7061 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7062 | }; |
| 7063 | |
| 7064 | MockRead data_reads1[] = { |
| 7065 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7066 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7067 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7068 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7069 | }; |
| 7070 | |
| 7071 | // Resend with authorization from MyRealm's cache. |
| 7072 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7073 | MockWrite( |
| 7074 | "GET /x/1 HTTP/1.1\r\n" |
| 7075 | "Host: www.example.org\r\n" |
| 7076 | "Connection: keep-alive\r\n" |
| 7077 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7078 | }; |
| 7079 | |
| 7080 | // Sever accepts the authorization. |
| 7081 | MockRead data_reads2[] = { |
| 7082 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7083 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7084 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7085 | }; |
| 7086 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7087 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7088 | data_writes1, arraysize(data_writes1)); |
| 7089 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7090 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7091 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7092 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7093 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7094 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7095 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7096 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7097 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7098 | |
| 7099 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7100 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7101 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7102 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7103 | TestCompletionCallback callback2; |
| 7104 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7105 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7106 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7107 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7108 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 7109 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7110 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7111 | ASSERT_TRUE(response); |
| 7112 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7113 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7114 | } |
| 7115 | |
| 7116 | // ------------------------------------------------------------------------ |
| 7117 | |
| 7118 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 7119 | // cached identity. Should invalidate and re-prompt. |
| 7120 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7121 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7122 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7123 | request.url = GURL("http://www.example.org/p/q/t"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7124 | request.load_flags = 0; |
| 7125 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7126 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7127 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7128 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7129 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7130 | MockWrite( |
| 7131 | "GET /p/q/t HTTP/1.1\r\n" |
| 7132 | "Host: www.example.org\r\n" |
| 7133 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7134 | }; |
| 7135 | |
| 7136 | MockRead data_reads1[] = { |
| 7137 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7138 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7139 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7140 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7141 | }; |
| 7142 | |
| 7143 | // Resend with authorization from cache for MyRealm. |
| 7144 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7145 | MockWrite( |
| 7146 | "GET /p/q/t HTTP/1.1\r\n" |
| 7147 | "Host: www.example.org\r\n" |
| 7148 | "Connection: keep-alive\r\n" |
| 7149 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7150 | }; |
| 7151 | |
| 7152 | // Sever rejects the authorization. |
| 7153 | MockRead data_reads2[] = { |
| 7154 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7155 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7156 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7157 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7158 | }; |
| 7159 | |
| 7160 | // At this point we should prompt for new credentials for MyRealm. |
| 7161 | // Restart with username=foo3, password=foo4. |
| 7162 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7163 | MockWrite( |
| 7164 | "GET /p/q/t HTTP/1.1\r\n" |
| 7165 | "Host: www.example.org\r\n" |
| 7166 | "Connection: keep-alive\r\n" |
| 7167 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7168 | }; |
| 7169 | |
| 7170 | // Sever accepts the authorization. |
| 7171 | MockRead data_reads3[] = { |
| 7172 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7173 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7174 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7175 | }; |
| 7176 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7177 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7178 | data_writes1, arraysize(data_writes1)); |
| 7179 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7180 | data_writes2, arraysize(data_writes2)); |
| 7181 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7182 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7183 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7184 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7185 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7186 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7187 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7188 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7189 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7190 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7191 | |
| 7192 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7193 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7194 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7195 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7196 | TestCompletionCallback callback2; |
| 7197 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7198 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7199 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7200 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7201 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 7202 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7203 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7204 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7205 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7206 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7207 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7208 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7209 | rv = trans->RestartWithAuth( |
| 7210 | AuthCredentials(kFoo3, kBar3), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7211 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7212 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7213 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7214 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7215 | |
| 7216 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7217 | ASSERT_TRUE(response); |
| 7218 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7219 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7220 | } |
| 7221 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7222 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7223 | // Tests that nonce count increments when multiple auth attempts |
| 7224 | // are started with the same nonce. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7225 | TEST_P(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 7226 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 7227 | new HttpAuthHandlerDigest::Factory(); |
| 7228 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 7229 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 7230 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7231 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7232 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7233 | |
| 7234 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7235 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7236 | HttpRequestInfo request; |
| 7237 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7238 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7239 | request.load_flags = 0; |
| 7240 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7241 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7242 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7243 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7244 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7245 | MockWrite( |
| 7246 | "GET /x/y/z HTTP/1.1\r\n" |
| 7247 | "Host: www.example.org\r\n" |
| 7248 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7249 | }; |
| 7250 | |
| 7251 | MockRead data_reads1[] = { |
| 7252 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7253 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 7254 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7255 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7256 | }; |
| 7257 | |
| 7258 | // Resend with authorization (username=foo, password=bar) |
| 7259 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7260 | MockWrite( |
| 7261 | "GET /x/y/z HTTP/1.1\r\n" |
| 7262 | "Host: www.example.org\r\n" |
| 7263 | "Connection: keep-alive\r\n" |
| 7264 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 7265 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 7266 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 7267 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7268 | }; |
| 7269 | |
| 7270 | // Sever accepts the authorization. |
| 7271 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 7272 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7273 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7274 | }; |
| 7275 | |
| 7276 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7277 | data_writes1, arraysize(data_writes1)); |
| 7278 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7279 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7280 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7281 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7282 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7283 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7284 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7285 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7286 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7287 | |
| 7288 | rv = callback1.WaitForResult(); |
| 7289 | EXPECT_EQ(OK, rv); |
| 7290 | |
| 7291 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7292 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7293 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7294 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7295 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7296 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7297 | rv = trans->RestartWithAuth( |
| 7298 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7299 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7300 | |
| 7301 | rv = callback2.WaitForResult(); |
| 7302 | EXPECT_EQ(OK, rv); |
| 7303 | |
| 7304 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7305 | ASSERT_TRUE(response); |
| 7306 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7307 | } |
| 7308 | |
| 7309 | // ------------------------------------------------------------------------ |
| 7310 | |
| 7311 | // Transaction 2: Request another resource in digestive's protection space. |
| 7312 | // This will preemptively add an Authorization header which should have an |
| 7313 | // "nc" value of 2 (as compared to 1 in the first use. |
| 7314 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7315 | HttpRequestInfo request; |
| 7316 | request.method = "GET"; |
| 7317 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7318 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7319 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7320 | request.load_flags = 0; |
| 7321 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7322 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7323 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7324 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7325 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7326 | MockWrite( |
| 7327 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7328 | "Host: www.example.org\r\n" |
| 7329 | "Connection: keep-alive\r\n" |
| 7330 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 7331 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 7332 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 7333 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7334 | }; |
| 7335 | |
| 7336 | // Sever accepts the authorization. |
| 7337 | MockRead data_reads1[] = { |
| 7338 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7339 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7340 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7341 | }; |
| 7342 | |
| 7343 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7344 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7345 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7346 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7347 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7348 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7349 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7350 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7351 | |
| 7352 | rv = callback1.WaitForResult(); |
| 7353 | EXPECT_EQ(OK, rv); |
| 7354 | |
| 7355 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7356 | ASSERT_TRUE(response); |
| 7357 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7358 | } |
| 7359 | } |
| 7360 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7361 | // Test the ResetStateForRestart() private method. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7362 | TEST_P(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7363 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7364 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7365 | std::unique_ptr<HttpNetworkTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7366 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7367 | |
| 7368 | // Setup some state (which we expect ResetStateForRestart() will clear). |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7369 | trans->read_buf_ = new IOBuffer(15); |
| 7370 | trans->read_buf_len_ = 15; |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 7371 | trans->request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7372 | |
| 7373 | // Setup state in response_ |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 7374 | HttpResponseInfo* response = &trans->response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7375 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7376 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7377 | response->response_time = base::Time::Now(); |
| 7378 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7379 | |
| 7380 | { // Setup state for response_.vary_data |
| 7381 | HttpRequestInfo request; |
| 7382 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 7383 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 7384 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7385 | request.extra_headers.SetHeader("Foo", "1"); |
| 7386 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7387 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7388 | } |
| 7389 | |
| 7390 | // Cause the above state to be reset. |
| 7391 | trans->ResetStateForRestart(); |
| 7392 | |
| 7393 | // Verify that the state that needed to be reset, has been reset. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7394 | EXPECT_FALSE(trans->read_buf_); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7395 | EXPECT_EQ(0, trans->read_buf_len_); |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 7396 | EXPECT_TRUE(trans->request_headers_.IsEmpty()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7397 | EXPECT_FALSE(response->auth_challenge); |
| 7398 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 7399 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7400 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7401 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7402 | } |
| 7403 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7404 | // Test HTTPS connections to a site with a bad certificate |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7405 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7406 | HttpRequestInfo request; |
| 7407 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7408 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7409 | request.load_flags = 0; |
| 7410 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7411 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7412 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7413 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7414 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7415 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7416 | MockWrite( |
| 7417 | "GET / HTTP/1.1\r\n" |
| 7418 | "Host: www.example.org\r\n" |
| 7419 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7420 | }; |
| 7421 | |
| 7422 | MockRead data_reads[] = { |
| 7423 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7424 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7425 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7426 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7427 | }; |
| 7428 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 7429 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7430 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7431 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7432 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7433 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7434 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7435 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7436 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7437 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7438 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7439 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7440 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7441 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7442 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7443 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7444 | |
| 7445 | rv = callback.WaitForResult(); |
| 7446 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 7447 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7448 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7449 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7450 | |
| 7451 | rv = callback.WaitForResult(); |
| 7452 | EXPECT_EQ(OK, rv); |
| 7453 | |
| 7454 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7455 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7456 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7457 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7458 | } |
| 7459 | |
| 7460 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 7461 | // proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7462 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7463 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7464 | |
| 7465 | HttpRequestInfo request; |
| 7466 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7467 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7468 | request.load_flags = 0; |
| 7469 | |
| 7470 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7471 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7472 | "Host: www.example.org:443\r\n" |
| 7473 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7474 | }; |
| 7475 | |
| 7476 | MockRead proxy_reads[] = { |
| 7477 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7478 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7479 | }; |
| 7480 | |
| 7481 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7482 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7483 | "Host: www.example.org:443\r\n" |
| 7484 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7485 | MockWrite("GET / HTTP/1.1\r\n" |
| 7486 | "Host: www.example.org\r\n" |
| 7487 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7488 | }; |
| 7489 | |
| 7490 | MockRead data_reads[] = { |
| 7491 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7492 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7493 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7494 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7495 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7496 | }; |
| 7497 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7498 | StaticSocketDataProvider ssl_bad_certificate( |
| 7499 | proxy_reads, arraysize(proxy_reads), |
| 7500 | proxy_writes, arraysize(proxy_writes)); |
| 7501 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7502 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7503 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7504 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7505 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7506 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7507 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7508 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7509 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7510 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7511 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7512 | |
| 7513 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7514 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7515 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7516 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7517 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7518 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7519 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7520 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7521 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7522 | |
| 7523 | rv = callback.WaitForResult(); |
| 7524 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 7525 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7526 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7527 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7528 | |
| 7529 | rv = callback.WaitForResult(); |
| 7530 | EXPECT_EQ(OK, rv); |
| 7531 | |
| 7532 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7533 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7534 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7535 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7536 | } |
| 7537 | } |
| 7538 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7539 | |
| 7540 | // Test HTTPS connections to a site, going through an HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7541 | TEST_P(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7542 | session_deps_.proxy_service = |
| 7543 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7544 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7545 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7546 | |
| 7547 | HttpRequestInfo request; |
| 7548 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7549 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7550 | request.load_flags = 0; |
| 7551 | |
| 7552 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7553 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7554 | "Host: www.example.org:443\r\n" |
| 7555 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7556 | MockWrite("GET / HTTP/1.1\r\n" |
| 7557 | "Host: www.example.org\r\n" |
| 7558 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7559 | }; |
| 7560 | |
| 7561 | MockRead data_reads[] = { |
| 7562 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7563 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7564 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7565 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7566 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7567 | }; |
| 7568 | |
| 7569 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7570 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7571 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 7572 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7573 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7574 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7575 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 7576 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7577 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7578 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7579 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7580 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7581 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7582 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7583 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7584 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7585 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7586 | |
| 7587 | rv = callback.WaitForResult(); |
| 7588 | EXPECT_EQ(OK, rv); |
| 7589 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7590 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7591 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7592 | |
| 7593 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7594 | EXPECT_EQ(200, response->headers->response_code()); |
| 7595 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7596 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7597 | |
| 7598 | LoadTimingInfo load_timing_info; |
| 7599 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7600 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7601 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7602 | } |
| 7603 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7604 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7605 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7606 | session_deps_.proxy_service = |
| 7607 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7608 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7609 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7610 | |
| 7611 | HttpRequestInfo request; |
| 7612 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7613 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7614 | request.load_flags = 0; |
| 7615 | |
| 7616 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7617 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7618 | "Host: www.example.org:443\r\n" |
| 7619 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7620 | }; |
| 7621 | |
| 7622 | MockRead data_reads[] = { |
| 7623 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 7624 | MockRead("Location: http://login.example.com/\r\n"), |
| 7625 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7626 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7627 | }; |
| 7628 | |
| 7629 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7630 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7631 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7632 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7633 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7634 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7635 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7636 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7637 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7638 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7639 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7640 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7641 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7642 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7643 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7644 | |
| 7645 | rv = callback.WaitForResult(); |
| 7646 | EXPECT_EQ(OK, rv); |
| 7647 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7648 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7649 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7650 | |
| 7651 | EXPECT_EQ(302, response->headers->response_code()); |
| 7652 | std::string url; |
| 7653 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7654 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7655 | |
| 7656 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 7657 | // timing for the proxy connection instead of the connection to the host, |
| 7658 | // and no send / receive times. |
| 7659 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 7660 | LoadTimingInfo load_timing_info; |
| 7661 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7662 | |
| 7663 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 7664 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7665 | |
| 7666 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 7667 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 7668 | load_timing_info.proxy_resolve_end); |
| 7669 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 7670 | load_timing_info.connect_timing.connect_start); |
| 7671 | ExpectConnectTimingHasTimes( |
| 7672 | load_timing_info.connect_timing, |
| 7673 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7674 | |
| 7675 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 7676 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 7677 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7678 | } |
| 7679 | |
| 7680 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7681 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7682 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7683 | |
| 7684 | HttpRequestInfo request; |
| 7685 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7686 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7687 | request.load_flags = 0; |
| 7688 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7689 | std::unique_ptr<SpdySerializedFrame> conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7690 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7691 | std::unique_ptr<SpdySerializedFrame> goaway( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7692 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7693 | MockWrite data_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7694 | CreateMockWrite(*conn.get(), 0, SYNCHRONOUS), |
| 7695 | CreateMockWrite(*goaway.get(), 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7696 | }; |
| 7697 | |
| 7698 | static const char* const kExtraHeaders[] = { |
| 7699 | "location", |
| 7700 | "http://login.example.com/", |
| 7701 | }; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7702 | std::unique_ptr<SpdySerializedFrame> resp( |
| 7703 | spdy_util_.ConstructSpdySynReplyError("302 Redirect", kExtraHeaders, |
| 7704 | arraysize(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7705 | MockRead data_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7706 | CreateMockRead(*resp.get(), 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7707 | }; |
| 7708 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7709 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7710 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7711 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7712 | proxy_ssl.SetNextProto(GetProtocol()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7713 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7714 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7715 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7716 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7717 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7718 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7719 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7720 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7721 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7722 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7723 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7724 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7725 | |
| 7726 | rv = callback.WaitForResult(); |
| 7727 | EXPECT_EQ(OK, rv); |
| 7728 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7729 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7730 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7731 | |
| 7732 | EXPECT_EQ(302, response->headers->response_code()); |
| 7733 | std::string url; |
| 7734 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7735 | EXPECT_EQ("http://login.example.com/", url); |
| 7736 | } |
| 7737 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7738 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7739 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7740 | ErrorResponseToHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7741 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7742 | |
| 7743 | HttpRequestInfo request; |
| 7744 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7745 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7746 | request.load_flags = 0; |
| 7747 | |
| 7748 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7749 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7750 | "Host: www.example.org:443\r\n" |
| 7751 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7752 | }; |
| 7753 | |
| 7754 | MockRead data_reads[] = { |
| 7755 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 7756 | MockRead("Content-Length: 23\r\n\r\n"), |
| 7757 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7758 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7759 | }; |
| 7760 | |
| 7761 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7762 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7763 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7764 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7765 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7766 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7767 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7768 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7769 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7770 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7771 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7772 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7773 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7774 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7775 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7776 | |
| 7777 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7778 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7779 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 7780 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7781 | } |
| 7782 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7783 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7784 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7785 | ErrorResponseToHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7786 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7787 | |
| 7788 | HttpRequestInfo request; |
| 7789 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7790 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7791 | request.load_flags = 0; |
| 7792 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7793 | std::unique_ptr<SpdySerializedFrame> conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7794 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7795 | std::unique_ptr<SpdySerializedFrame> rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7796 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7797 | MockWrite data_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7798 | CreateMockWrite(*conn.get(), 0), CreateMockWrite(*rst.get(), 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7799 | }; |
| 7800 | |
| 7801 | static const char* const kExtraHeaders[] = { |
| 7802 | "location", |
| 7803 | "http://login.example.com/", |
| 7804 | }; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7805 | std::unique_ptr<SpdySerializedFrame> resp( |
| 7806 | spdy_util_.ConstructSpdySynReplyError("404 Not Found", kExtraHeaders, |
| 7807 | arraysize(kExtraHeaders) / 2, 1)); |
| 7808 | std::unique_ptr<SpdySerializedFrame> body(spdy_util_.ConstructSpdyBodyFrame( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 7809 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7810 | MockRead data_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7811 | CreateMockRead(*resp.get(), 1), |
| 7812 | CreateMockRead(*body.get(), 2), |
| 7813 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7814 | }; |
| 7815 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7816 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7817 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7818 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7819 | proxy_ssl.SetNextProto(GetProtocol()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7820 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7821 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7822 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7823 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7824 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7825 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7826 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7827 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7828 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7829 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7830 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7831 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7832 | |
| 7833 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7834 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7835 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 7836 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7837 | } |
| 7838 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7839 | // Test the request-challenge-retry sequence for basic auth, through |
| 7840 | // a SPDY proxy over a single SPDY session. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7841 | TEST_P(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7842 | HttpRequestInfo request; |
| 7843 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7844 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7845 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 7846 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7847 | |
| 7848 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7849 | session_deps_.proxy_service = |
| 7850 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7851 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7852 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7853 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7854 | |
| 7855 | // Since we have proxy, should try to establish tunnel. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7856 | std::unique_ptr<SpdySerializedFrame> req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7857 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7858 | std::unique_ptr<SpdySerializedFrame> rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7859 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7860 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7861 | |
| 7862 | // After calling trans->RestartWithAuth(), this is the request we should |
| 7863 | // be issuing -- the final header line contains the credentials. |
| 7864 | const char* const kAuthCredentials[] = { |
| 7865 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 7866 | }; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7867 | std::unique_ptr<SpdySerializedFrame> connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 7868 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7869 | HostPortPair("www.example.org", 443))); |
| 7870 | // fetch https://www.example.org/ via HTTP |
| 7871 | const char get[] = |
| 7872 | "GET / HTTP/1.1\r\n" |
| 7873 | "Host: www.example.org\r\n" |
| 7874 | "Connection: keep-alive\r\n\r\n"; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7875 | std::unique_ptr<SpdySerializedFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7876 | spdy_util_.ConstructSpdyBodyFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7877 | |
| 7878 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7879 | CreateMockWrite(*req, 0, ASYNC), |
| 7880 | CreateMockWrite(*rst, 2, ASYNC), |
| 7881 | CreateMockWrite(*connect2, 3), |
| 7882 | CreateMockWrite(*wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7883 | }; |
| 7884 | |
| 7885 | // The proxy responds to the connect with a 407, using a persistent |
| 7886 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 7887 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7888 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7889 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 7890 | }; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7891 | std::unique_ptr<SpdySerializedFrame> conn_auth_resp( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 7892 | spdy_util_.ConstructSpdySynReplyError(kAuthStatus, kAuthChallenge, |
| 7893 | arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7894 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7895 | std::unique_ptr<SpdySerializedFrame> conn_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7896 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7897 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 7898 | "Content-Length: 5\r\n\r\n"; |
| 7899 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7900 | std::unique_ptr<SpdySerializedFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7901 | spdy_util_.ConstructSpdyBodyFrame(3, resp, strlen(resp), false)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7902 | std::unique_ptr<SpdySerializedFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7903 | spdy_util_.ConstructSpdyBodyFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7904 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7905 | CreateMockRead(*conn_auth_resp, 1, ASYNC), |
| 7906 | CreateMockRead(*conn_resp, 4, ASYNC), |
| 7907 | CreateMockRead(*wrapped_get_resp, 6, ASYNC), |
| 7908 | CreateMockRead(*wrapped_body, 7, ASYNC), |
| 7909 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7910 | }; |
| 7911 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7912 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7913 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7914 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7915 | // Negotiate SPDY to the proxy |
| 7916 | SSLSocketDataProvider proxy(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7917 | proxy.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7918 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7919 | // Vanilla SSL to the server |
| 7920 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7921 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7922 | |
| 7923 | TestCompletionCallback callback1; |
| 7924 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7925 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7926 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7927 | |
| 7928 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 7929 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7930 | |
| 7931 | rv = callback1.WaitForResult(); |
| 7932 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 7933 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7934 | log.GetEntries(&entries); |
| 7935 | size_t pos = ExpectLogContainsSomewhere( |
| 7936 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 7937 | NetLog::PHASE_NONE); |
| 7938 | ExpectLogContainsSomewhere( |
| 7939 | entries, pos, |
| 7940 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 7941 | NetLog::PHASE_NONE); |
| 7942 | |
| 7943 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7944 | ASSERT_TRUE(response); |
| 7945 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7946 | EXPECT_EQ(407, response->headers->response_code()); |
| 7947 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7948 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7949 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 7950 | |
| 7951 | TestCompletionCallback callback2; |
| 7952 | |
| 7953 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7954 | callback2.callback()); |
| 7955 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7956 | |
| 7957 | rv = callback2.WaitForResult(); |
| 7958 | EXPECT_EQ(OK, rv); |
| 7959 | |
| 7960 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7961 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7962 | |
| 7963 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7964 | EXPECT_EQ(200, response->headers->response_code()); |
| 7965 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 7966 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7967 | |
| 7968 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7969 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7970 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7971 | LoadTimingInfo load_timing_info; |
| 7972 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7973 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7974 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7975 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7976 | trans.reset(); |
| 7977 | session->CloseAllConnections(); |
| 7978 | } |
| 7979 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7980 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 7981 | // origin that is different from that of its associated resource. |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 7982 | TEST_P(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
| 7983 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7984 | std::unique_ptr<TestProxyDelegate> proxy_delegate(new TestProxyDelegate()); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 7985 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 7986 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7987 | HttpRequestInfo request; |
| 7988 | HttpRequestInfo push_request; |
| 7989 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7990 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7991 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7992 | push_request.method = "GET"; |
| 7993 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 7994 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 7995 | // Configure against https proxy server "myproxy:443". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7996 | session_deps_.proxy_service = |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 7997 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7998 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7999 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8000 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8001 | session_deps_.proxy_delegate.reset(proxy_delegate.release()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8002 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8003 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8004 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8005 | std::unique_ptr<SpdySerializedFrame> stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 8006 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, false)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8007 | |
| 8008 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8009 | CreateMockWrite(*stream1_syn, 0, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8010 | }; |
| 8011 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8012 | std::unique_ptr<SpdySerializedFrame> stream1_reply( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8013 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8014 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8015 | std::unique_ptr<SpdySerializedFrame> stream1_body( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8016 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8017 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8018 | std::unique_ptr<SpdySerializedFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8019 | NULL, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8020 | const char kPushedData[] = "pushed"; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8021 | std::unique_ptr<SpdySerializedFrame> stream2_body( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8022 | spdy_util_.ConstructSpdyBodyFrame(2, kPushedData, strlen(kPushedData), |
| 8023 | true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8024 | |
| 8025 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8026 | CreateMockRead(*stream1_reply, 1, ASYNC), |
| 8027 | CreateMockRead(*stream2_syn, 2, ASYNC), |
| 8028 | CreateMockRead(*stream1_body, 3, ASYNC), |
| 8029 | CreateMockRead(*stream2_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 8030 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8031 | }; |
| 8032 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8033 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8034 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8035 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8036 | // Negotiate SPDY to the proxy |
| 8037 | SSLSocketDataProvider proxy(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8038 | proxy.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8039 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8040 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8041 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8042 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8043 | TestCompletionCallback callback; |
| 8044 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 8045 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8046 | |
| 8047 | rv = callback.WaitForResult(); |
| 8048 | EXPECT_EQ(OK, rv); |
| 8049 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8050 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8051 | std::unique_ptr<HttpTransaction> push_trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8052 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8053 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8054 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8055 | |
| 8056 | rv = callback.WaitForResult(); |
| 8057 | EXPECT_EQ(OK, rv); |
| 8058 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 8059 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8060 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8061 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8062 | |
| 8063 | EXPECT_EQ(200, response->headers->response_code()); |
| 8064 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8065 | |
| 8066 | std::string response_data; |
| 8067 | rv = ReadTransaction(trans.get(), &response_data); |
| 8068 | EXPECT_EQ(OK, rv); |
| 8069 | EXPECT_EQ("hello!", response_data); |
| 8070 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8071 | LoadTimingInfo load_timing_info; |
| 8072 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8073 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8074 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8075 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8076 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8077 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8078 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 8079 | |
| 8080 | rv = ReadTransaction(push_trans.get(), &response_data); |
| 8081 | EXPECT_EQ(OK, rv); |
| 8082 | EXPECT_EQ("pushed", response_data); |
| 8083 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8084 | LoadTimingInfo push_load_timing_info; |
| 8085 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 8086 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 8087 | // The transactions should share a socket ID, despite being for different |
| 8088 | // origins. |
| 8089 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 8090 | push_load_timing_info.socket_log_id); |
| 8091 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8092 | trans.reset(); |
| 8093 | push_trans.reset(); |
| 8094 | session->CloseAllConnections(); |
| 8095 | } |
| 8096 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8097 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8098 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8099 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8100 | std::unique_ptr<TestProxyDelegate> proxy_delegate(new TestProxyDelegate()); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8101 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 8102 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8103 | HttpRequestInfo request; |
| 8104 | |
| 8105 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8106 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8107 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8108 | session_deps_.proxy_service = |
| 8109 | ProxyService::CreateFixed("https://myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8110 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8111 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8112 | |
| 8113 | // Enable cross-origin push. |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8114 | session_deps_.proxy_delegate.reset(proxy_delegate.release()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8115 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8116 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8117 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8118 | std::unique_ptr<SpdySerializedFrame> stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 8119 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, false)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8120 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8121 | std::unique_ptr<SpdySerializedFrame> push_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 8122 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8123 | |
| 8124 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8125 | CreateMockWrite(*stream1_syn, 0, ASYNC), CreateMockWrite(*push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8126 | }; |
| 8127 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8128 | std::unique_ptr<SpdySerializedFrame> stream1_reply( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8129 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8130 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8131 | std::unique_ptr<SpdySerializedFrame> stream1_body( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8132 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8133 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8134 | std::unique_ptr<SpdySerializedFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8135 | NULL, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8136 | |
| 8137 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8138 | CreateMockRead(*stream1_reply, 1, ASYNC), |
| 8139 | CreateMockRead(*stream2_syn, 2, ASYNC), |
| 8140 | CreateMockRead(*stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 8141 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8142 | }; |
| 8143 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8144 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8145 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8146 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8147 | // Negotiate SPDY to the proxy |
| 8148 | SSLSocketDataProvider proxy(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8149 | proxy.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8150 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8151 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8152 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8153 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8154 | TestCompletionCallback callback; |
| 8155 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 8156 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8157 | |
| 8158 | rv = callback.WaitForResult(); |
| 8159 | EXPECT_EQ(OK, rv); |
| 8160 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8161 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8162 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8163 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8164 | |
| 8165 | EXPECT_EQ(200, response->headers->response_code()); |
| 8166 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8167 | |
| 8168 | std::string response_data; |
| 8169 | rv = ReadTransaction(trans.get(), &response_data); |
| 8170 | EXPECT_EQ(OK, rv); |
| 8171 | EXPECT_EQ("hello!", response_data); |
| 8172 | |
| 8173 | trans.reset(); |
| 8174 | session->CloseAllConnections(); |
| 8175 | } |
| 8176 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8177 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 8178 | // resources. |
| 8179 | TEST_P(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8180 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8181 | std::unique_ptr<TestProxyDelegate> proxy_delegate(new TestProxyDelegate()); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8182 | proxy_delegate->set_trusted_spdy_proxy( |
| 8183 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 8184 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8185 | HttpRequestInfo request; |
| 8186 | |
| 8187 | request.method = "GET"; |
| 8188 | request.url = GURL("http://www.example.org/"); |
| 8189 | |
| 8190 | // Configure against https proxy server "myproxy:70". |
| 8191 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
| 8192 | BoundTestNetLog log; |
| 8193 | session_deps_.net_log = log.bound().net_log(); |
| 8194 | |
| 8195 | // Enable cross-origin push. |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8196 | session_deps_.proxy_delegate.reset(proxy_delegate.release()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8197 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8198 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8199 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8200 | std::unique_ptr<SpdySerializedFrame> stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 8201 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, false)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8202 | |
| 8203 | MockWrite spdy_writes[] = { |
| 8204 | CreateMockWrite(*stream1_syn, 0, ASYNC), |
| 8205 | }; |
| 8206 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8207 | std::unique_ptr<SpdySerializedFrame> stream1_reply( |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8208 | spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
| 8209 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8210 | std::unique_ptr<SpdySerializedFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 8211 | nullptr, 0, 2, 1, "https://myproxy:70/foo.dat")); |
| 8212 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8213 | std::unique_ptr<SpdySerializedFrame> stream1_body( |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8214 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 8215 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8216 | std::unique_ptr<SpdySerializedFrame> stream2_reply( |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8217 | spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
| 8218 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8219 | std::unique_ptr<SpdySerializedFrame> stream2_body( |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8220 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 8221 | |
| 8222 | MockRead spdy_reads[] = { |
| 8223 | CreateMockRead(*stream1_reply, 1, ASYNC), |
| 8224 | CreateMockRead(*stream2_syn, 2, ASYNC), |
| 8225 | CreateMockRead(*stream1_body, 3, ASYNC), |
| 8226 | CreateMockRead(*stream2_body, 4, ASYNC), |
| 8227 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
| 8228 | }; |
| 8229 | |
| 8230 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8231 | arraysize(spdy_writes)); |
| 8232 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 8233 | // Negotiate SPDY to the proxy |
| 8234 | SSLSocketDataProvider proxy(ASYNC, OK); |
| 8235 | proxy.SetNextProto(GetProtocol()); |
| 8236 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 8237 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8238 | std::unique_ptr<HttpTransaction> trans( |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8239 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8240 | TestCompletionCallback callback; |
| 8241 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 8242 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8243 | |
| 8244 | rv = callback.WaitForResult(); |
| 8245 | EXPECT_EQ(OK, rv); |
| 8246 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8247 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8248 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8249 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8250 | |
| 8251 | EXPECT_EQ(200, response->headers->response_code()); |
| 8252 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8253 | |
| 8254 | std::string response_data; |
| 8255 | rv = ReadTransaction(trans.get(), &response_data); |
| 8256 | EXPECT_EQ(OK, rv); |
| 8257 | EXPECT_EQ("hello!", response_data); |
| 8258 | |
| 8259 | trans.reset(); |
| 8260 | session->CloseAllConnections(); |
| 8261 | } |
| 8262 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8263 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 8264 | // HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8265 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8266 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8267 | |
| 8268 | HttpRequestInfo request; |
| 8269 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8270 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8271 | request.load_flags = 0; |
| 8272 | |
| 8273 | // Attempt to fetch the URL from a server with a bad cert |
| 8274 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8275 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8276 | "Host: www.example.org:443\r\n" |
| 8277 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8278 | }; |
| 8279 | |
| 8280 | MockRead bad_cert_reads[] = { |
| 8281 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8282 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8283 | }; |
| 8284 | |
| 8285 | // Attempt to fetch the URL with a good cert |
| 8286 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8287 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8288 | "Host: www.example.org:443\r\n" |
| 8289 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8290 | MockWrite("GET / HTTP/1.1\r\n" |
| 8291 | "Host: www.example.org\r\n" |
| 8292 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8293 | }; |
| 8294 | |
| 8295 | MockRead good_cert_reads[] = { |
| 8296 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8297 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8298 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8299 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8300 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8301 | }; |
| 8302 | |
| 8303 | StaticSocketDataProvider ssl_bad_certificate( |
| 8304 | bad_cert_reads, arraysize(bad_cert_reads), |
| 8305 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 8306 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 8307 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8308 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8309 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8310 | |
| 8311 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8312 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8313 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8314 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8315 | |
| 8316 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8317 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8318 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8319 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8320 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8321 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8322 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8323 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8324 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8325 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8326 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8327 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8328 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8329 | |
| 8330 | rv = callback.WaitForResult(); |
| 8331 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 8332 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8333 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8334 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8335 | |
| 8336 | rv = callback.WaitForResult(); |
| 8337 | EXPECT_EQ(OK, rv); |
| 8338 | |
| 8339 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8340 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8341 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8342 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8343 | } |
| 8344 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8345 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8346 | HttpRequestInfo request; |
| 8347 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8348 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8349 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8350 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8351 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8352 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8353 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8354 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8355 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8356 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8357 | MockWrite( |
| 8358 | "GET / HTTP/1.1\r\n" |
| 8359 | "Host: www.example.org\r\n" |
| 8360 | "Connection: keep-alive\r\n" |
| 8361 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8362 | }; |
| 8363 | |
| 8364 | // Lastly, the server responds with the actual content. |
| 8365 | MockRead data_reads[] = { |
| 8366 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8367 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8368 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8369 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8370 | }; |
| 8371 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8372 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8373 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8374 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8375 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8376 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8377 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8378 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8379 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8380 | |
| 8381 | rv = callback.WaitForResult(); |
| 8382 | EXPECT_EQ(OK, rv); |
| 8383 | } |
| 8384 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8385 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8386 | HttpRequestInfo request; |
| 8387 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8388 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8389 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8390 | "Chromium Ultra Awesome X Edition"); |
| 8391 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8392 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8393 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8394 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8395 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8396 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8397 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8398 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8399 | "Host: www.example.org:443\r\n" |
| 8400 | "Proxy-Connection: keep-alive\r\n" |
| 8401 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8402 | }; |
| 8403 | MockRead data_reads[] = { |
| 8404 | // Return an error, so the transaction stops here (this test isn't |
| 8405 | // interested in the rest). |
| 8406 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 8407 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8408 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 8409 | }; |
| 8410 | |
| 8411 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8412 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8413 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8414 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8415 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8416 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8417 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8418 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8419 | |
| 8420 | rv = callback.WaitForResult(); |
| 8421 | EXPECT_EQ(OK, rv); |
| 8422 | } |
| 8423 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8424 | TEST_P(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8425 | HttpRequestInfo request; |
| 8426 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8427 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8428 | request.load_flags = 0; |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 8429 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 8430 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8431 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8432 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8433 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8434 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8435 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8436 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8437 | MockWrite( |
| 8438 | "GET / HTTP/1.1\r\n" |
| 8439 | "Host: www.example.org\r\n" |
| 8440 | "Connection: keep-alive\r\n" |
| 8441 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8442 | }; |
| 8443 | |
| 8444 | // Lastly, the server responds with the actual content. |
| 8445 | MockRead data_reads[] = { |
| 8446 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8447 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8448 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8449 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8450 | }; |
| 8451 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8452 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8453 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8454 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8455 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8456 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8457 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8458 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8459 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8460 | |
| 8461 | rv = callback.WaitForResult(); |
| 8462 | EXPECT_EQ(OK, rv); |
| 8463 | } |
| 8464 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8465 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8466 | HttpRequestInfo request; |
| 8467 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8468 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8469 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8470 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8471 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8472 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8473 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8474 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8475 | MockWrite( |
| 8476 | "POST / HTTP/1.1\r\n" |
| 8477 | "Host: www.example.org\r\n" |
| 8478 | "Connection: keep-alive\r\n" |
| 8479 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8480 | }; |
| 8481 | |
| 8482 | // Lastly, the server responds with the actual content. |
| 8483 | MockRead data_reads[] = { |
| 8484 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8485 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8486 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8487 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [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] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8493 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8494 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [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] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8497 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8498 | |
| 8499 | rv = callback.WaitForResult(); |
| 8500 | EXPECT_EQ(OK, rv); |
| 8501 | } |
| 8502 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8503 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8504 | HttpRequestInfo request; |
| 8505 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8506 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8507 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8508 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8509 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8510 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8511 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8512 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8513 | MockWrite( |
| 8514 | "PUT / HTTP/1.1\r\n" |
| 8515 | "Host: www.example.org\r\n" |
| 8516 | "Connection: keep-alive\r\n" |
| 8517 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8518 | }; |
| 8519 | |
| 8520 | // Lastly, the server responds with the actual content. |
| 8521 | MockRead data_reads[] = { |
| 8522 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8523 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8524 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8525 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8526 | }; |
| 8527 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8528 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8529 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8530 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8531 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8532 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8533 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8534 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8535 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8536 | |
| 8537 | rv = callback.WaitForResult(); |
| 8538 | EXPECT_EQ(OK, rv); |
| 8539 | } |
| 8540 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8541 | TEST_P(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8542 | HttpRequestInfo request; |
| 8543 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8544 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8545 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8546 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8547 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8548 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8549 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8550 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 8551 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 8552 | "Host: www.example.org\r\n" |
| 8553 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8554 | }; |
| 8555 | |
| 8556 | // Lastly, the server responds with the actual content. |
| 8557 | MockRead data_reads[] = { |
| 8558 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8559 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8560 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8561 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8562 | }; |
| 8563 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8564 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8565 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8566 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8567 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8568 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8569 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8570 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8571 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8572 | |
| 8573 | rv = callback.WaitForResult(); |
| 8574 | EXPECT_EQ(OK, rv); |
| 8575 | } |
| 8576 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8577 | TEST_P(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8578 | HttpRequestInfo request; |
| 8579 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8580 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8581 | request.load_flags = LOAD_BYPASS_CACHE; |
| 8582 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8583 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8584 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8585 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8586 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8587 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8588 | MockWrite( |
| 8589 | "GET / HTTP/1.1\r\n" |
| 8590 | "Host: www.example.org\r\n" |
| 8591 | "Connection: keep-alive\r\n" |
| 8592 | "Pragma: no-cache\r\n" |
| 8593 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8594 | }; |
| 8595 | |
| 8596 | // Lastly, the server responds with the actual content. |
| 8597 | MockRead data_reads[] = { |
| 8598 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8599 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8600 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8601 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8602 | }; |
| 8603 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8604 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8605 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8606 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8607 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8608 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8609 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8610 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8611 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8612 | |
| 8613 | rv = callback.WaitForResult(); |
| 8614 | EXPECT_EQ(OK, rv); |
| 8615 | } |
| 8616 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8617 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8618 | BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8619 | HttpRequestInfo request; |
| 8620 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8621 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8622 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 8623 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8624 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8625 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8626 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8627 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8628 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8629 | MockWrite( |
| 8630 | "GET / HTTP/1.1\r\n" |
| 8631 | "Host: www.example.org\r\n" |
| 8632 | "Connection: keep-alive\r\n" |
| 8633 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8634 | }; |
| 8635 | |
| 8636 | // Lastly, the server responds with the actual content. |
| 8637 | MockRead data_reads[] = { |
| 8638 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8639 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8640 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8641 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8642 | }; |
| 8643 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8644 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8645 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8646 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8647 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8648 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8649 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8650 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8651 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8652 | |
| 8653 | rv = callback.WaitForResult(); |
| 8654 | EXPECT_EQ(OK, rv); |
| 8655 | } |
| 8656 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8657 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8658 | HttpRequestInfo request; |
| 8659 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8660 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8661 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8662 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8663 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8664 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8665 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8666 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8667 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8668 | MockWrite( |
| 8669 | "GET / HTTP/1.1\r\n" |
| 8670 | "Host: www.example.org\r\n" |
| 8671 | "Connection: keep-alive\r\n" |
| 8672 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8673 | }; |
| 8674 | |
| 8675 | // Lastly, the server responds with the actual content. |
| 8676 | MockRead data_reads[] = { |
| 8677 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8678 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8679 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8680 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8681 | }; |
| 8682 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8683 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8684 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8685 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8686 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8687 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8688 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8689 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8690 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8691 | |
| 8692 | rv = callback.WaitForResult(); |
| 8693 | EXPECT_EQ(OK, rv); |
| 8694 | } |
| 8695 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8696 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8697 | HttpRequestInfo request; |
| 8698 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8699 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8700 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 8701 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 8702 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8703 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8704 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8705 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8706 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8707 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8708 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8709 | MockWrite( |
| 8710 | "GET / HTTP/1.1\r\n" |
| 8711 | "Host: www.example.org\r\n" |
| 8712 | "Connection: keep-alive\r\n" |
| 8713 | "referer: www.foo.com\r\n" |
| 8714 | "hEllo: Kitty\r\n" |
| 8715 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8716 | }; |
| 8717 | |
| 8718 | // Lastly, the server responds with the actual content. |
| 8719 | MockRead data_reads[] = { |
| 8720 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8721 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8722 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8723 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8724 | }; |
| 8725 | |
| 8726 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8727 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8728 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8729 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8730 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8731 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8732 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8733 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8734 | |
| 8735 | rv = callback.WaitForResult(); |
| 8736 | EXPECT_EQ(OK, rv); |
| 8737 | } |
| 8738 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8739 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8740 | HttpRequestInfo request; |
| 8741 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8742 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8743 | request.load_flags = 0; |
| 8744 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8745 | session_deps_.proxy_service = |
| 8746 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8747 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8748 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8749 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8750 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8751 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8752 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8753 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8754 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 8755 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8756 | |
| 8757 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8758 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 8759 | MockWrite( |
| 8760 | "GET / HTTP/1.1\r\n" |
| 8761 | "Host: www.example.org\r\n" |
| 8762 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8763 | |
| 8764 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8765 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8766 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8767 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8768 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8769 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8770 | }; |
| 8771 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8772 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8773 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8774 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8775 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8776 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8777 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8778 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8779 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8780 | |
| 8781 | rv = callback.WaitForResult(); |
| 8782 | EXPECT_EQ(OK, rv); |
| 8783 | |
| 8784 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8785 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8786 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8787 | LoadTimingInfo load_timing_info; |
| 8788 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8789 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8790 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8791 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8792 | std::string response_text; |
| 8793 | rv = ReadTransaction(trans.get(), &response_text); |
| 8794 | EXPECT_EQ(OK, rv); |
| 8795 | EXPECT_EQ("Payload", response_text); |
| 8796 | } |
| 8797 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8798 | TEST_P(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8799 | HttpRequestInfo request; |
| 8800 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8801 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8802 | request.load_flags = 0; |
| 8803 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8804 | session_deps_.proxy_service = |
| 8805 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8806 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8807 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8808 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8809 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8810 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8811 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8812 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8813 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 8814 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8815 | |
| 8816 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8817 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 8818 | arraysize(write_buffer)), |
| 8819 | MockWrite( |
| 8820 | "GET / HTTP/1.1\r\n" |
| 8821 | "Host: www.example.org\r\n" |
| 8822 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8823 | |
| 8824 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8825 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 8826 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8827 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8828 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8829 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8830 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8831 | }; |
| 8832 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8833 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8834 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8835 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8836 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8837 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8838 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8839 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8840 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8841 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8842 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8843 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8844 | |
| 8845 | rv = callback.WaitForResult(); |
| 8846 | EXPECT_EQ(OK, rv); |
| 8847 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8848 | LoadTimingInfo load_timing_info; |
| 8849 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8850 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8851 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8852 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8853 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8854 | ASSERT_TRUE(response); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8855 | |
| 8856 | std::string response_text; |
| 8857 | rv = ReadTransaction(trans.get(), &response_text); |
| 8858 | EXPECT_EQ(OK, rv); |
| 8859 | EXPECT_EQ("Payload", response_text); |
| 8860 | } |
| 8861 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8862 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8863 | HttpRequestInfo request; |
| 8864 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8865 | request.url = GURL("http://www.example.org/"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8866 | request.load_flags = 0; |
| 8867 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8868 | session_deps_.proxy_service = |
| 8869 | ProxyService::CreateFixed("socks4://myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8870 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8871 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8872 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8873 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8874 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8875 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8876 | |
| 8877 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 8878 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8879 | |
| 8880 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8881 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 8882 | MockWrite( |
| 8883 | "GET / HTTP/1.1\r\n" |
| 8884 | "Host: www.example.org\r\n" |
| 8885 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8886 | |
| 8887 | MockRead data_reads[] = { |
| 8888 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 8889 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8890 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8891 | MockRead("Payload"), |
| 8892 | MockRead(SYNCHRONOUS, OK) |
| 8893 | }; |
| 8894 | |
| 8895 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8896 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8897 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8898 | |
| 8899 | TestCompletionCallback callback; |
| 8900 | |
| 8901 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8902 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8903 | |
| 8904 | rv = callback.WaitForResult(); |
| 8905 | EXPECT_EQ(OK, rv); |
| 8906 | |
| 8907 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8908 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8909 | |
| 8910 | LoadTimingInfo load_timing_info; |
| 8911 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8912 | TestLoadTimingNotReused(load_timing_info, |
| 8913 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8914 | |
| 8915 | std::string response_text; |
| 8916 | rv = ReadTransaction(trans.get(), &response_text); |
| 8917 | EXPECT_EQ(OK, rv); |
| 8918 | EXPECT_EQ("Payload", response_text); |
| 8919 | } |
| 8920 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8921 | TEST_P(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8922 | HttpRequestInfo request; |
| 8923 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8924 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8925 | request.load_flags = 0; |
| 8926 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8927 | session_deps_.proxy_service = |
| 8928 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8929 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8930 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8931 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8932 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8933 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8934 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8935 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8936 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 8937 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8938 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8939 | 0x05, // Version |
| 8940 | 0x01, // Command (CONNECT) |
| 8941 | 0x00, // Reserved. |
| 8942 | 0x03, // Address type (DOMAINNAME). |
| 8943 | 0x0F, // Length of domain (15) |
| 8944 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 8945 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8946 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8947 | const char kSOCKS5OkResponse[] = |
| 8948 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 8949 | |
| 8950 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8951 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 8952 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 8953 | MockWrite( |
| 8954 | "GET / HTTP/1.1\r\n" |
| 8955 | "Host: www.example.org\r\n" |
| 8956 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8957 | |
| 8958 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8959 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 8960 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8961 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8962 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8963 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8964 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8965 | }; |
| 8966 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8967 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8968 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8969 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8970 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8971 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8972 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8973 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8974 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8975 | |
| 8976 | rv = callback.WaitForResult(); |
| 8977 | EXPECT_EQ(OK, rv); |
| 8978 | |
| 8979 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8980 | ASSERT_TRUE(response); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8981 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8982 | LoadTimingInfo load_timing_info; |
| 8983 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8984 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8985 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8986 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8987 | std::string response_text; |
| 8988 | rv = ReadTransaction(trans.get(), &response_text); |
| 8989 | EXPECT_EQ(OK, rv); |
| 8990 | EXPECT_EQ("Payload", response_text); |
| 8991 | } |
| 8992 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8993 | TEST_P(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8994 | HttpRequestInfo request; |
| 8995 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8996 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8997 | request.load_flags = 0; |
| 8998 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8999 | session_deps_.proxy_service = |
| 9000 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9001 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9002 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9003 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9004 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9005 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9006 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9007 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9008 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 9009 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9010 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9011 | 0x05, // Version |
| 9012 | 0x01, // Command (CONNECT) |
| 9013 | 0x00, // Reserved. |
| 9014 | 0x03, // Address type (DOMAINNAME). |
| 9015 | 0x0F, // Length of domain (15) |
| 9016 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 9017 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9018 | }; |
| 9019 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9020 | const char kSOCKS5OkResponse[] = |
| 9021 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 9022 | |
| 9023 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9024 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 9025 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 9026 | arraysize(kSOCKS5OkRequest)), |
| 9027 | MockWrite( |
| 9028 | "GET / HTTP/1.1\r\n" |
| 9029 | "Host: www.example.org\r\n" |
| 9030 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9031 | |
| 9032 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9033 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 9034 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9035 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9036 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9037 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9038 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9039 | }; |
| 9040 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9041 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9042 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9043 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9044 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9045 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9046 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9047 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9048 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9049 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9050 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9051 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9052 | |
| 9053 | rv = callback.WaitForResult(); |
| 9054 | EXPECT_EQ(OK, rv); |
| 9055 | |
| 9056 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9057 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9058 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9059 | LoadTimingInfo load_timing_info; |
| 9060 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 9061 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9062 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9063 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9064 | std::string response_text; |
| 9065 | rv = ReadTransaction(trans.get(), &response_text); |
| 9066 | EXPECT_EQ(OK, rv); |
| 9067 | EXPECT_EQ("Payload", response_text); |
| 9068 | } |
| 9069 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9070 | namespace { |
| 9071 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9072 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9073 | |
| 9074 | struct GroupNameTest { |
| 9075 | std::string proxy_server; |
| 9076 | std::string url; |
| 9077 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9078 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9079 | }; |
| 9080 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9081 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9082 | NextProto next_proto, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9083 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9084 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9085 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9086 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9087 | session->http_server_properties(); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9088 | AlternativeService alternative_service( |
bnc | 4988e43 | 2015-03-31 03:06:25 | [diff] [blame] | 9089 | AlternateProtocolFromNextProto(next_proto), "", 443); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9090 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9091 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 9092 | url::SchemeHostPort("http", "host.with.alternate", 80), |
| 9093 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9094 | |
| 9095 | return session; |
| 9096 | } |
| 9097 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9098 | int GroupNameTransactionHelper(const std::string& url, |
| 9099 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9100 | HttpRequestInfo request; |
| 9101 | request.method = "GET"; |
| 9102 | request.url = GURL(url); |
| 9103 | request.load_flags = 0; |
| 9104 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9105 | std::unique_ptr<HttpTransaction> trans( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9106 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9107 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9108 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9109 | |
| 9110 | // We do not complete this request, the dtor will clean the transaction up. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9111 | return trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9112 | } |
| 9113 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9114 | } // namespace |
| 9115 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9116 | TEST_P(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9117 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9118 | { |
| 9119 | "", // unused |
| 9120 | "http://www.example.org/direct", |
| 9121 | "www.example.org:80", |
| 9122 | false, |
| 9123 | }, |
| 9124 | { |
| 9125 | "", // unused |
| 9126 | "http://[2001:1418:13:1::25]/direct", |
| 9127 | "[2001:1418:13:1::25]:80", |
| 9128 | false, |
| 9129 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9130 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9131 | // SSL Tests |
| 9132 | { |
| 9133 | "", // unused |
| 9134 | "https://www.example.org/direct_ssl", |
| 9135 | "ssl/www.example.org:443", |
| 9136 | true, |
| 9137 | }, |
| 9138 | { |
| 9139 | "", // unused |
| 9140 | "https://[2001:1418:13:1::25]/direct", |
| 9141 | "ssl/[2001:1418:13:1::25]:443", |
| 9142 | true, |
| 9143 | }, |
| 9144 | { |
| 9145 | "", // unused |
| 9146 | "http://host.with.alternate/direct", |
| 9147 | "ssl/host.with.alternate:443", |
| 9148 | true, |
| 9149 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9150 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9151 | |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 9152 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9153 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9154 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9155 | session_deps_.proxy_service = |
| 9156 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9157 | std::unique_ptr<HttpNetworkSession> session( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9158 | SetupSessionForGroupNameTests(GetProtocol(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9159 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9160 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9161 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
| 9162 | new CaptureGroupNameTransportSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9163 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9164 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9165 | std::unique_ptr<MockClientSocketPoolManager> mock_pool_manager( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 9166 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9167 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 9168 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9169 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9170 | |
| 9171 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9172 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9173 | if (tests[i].ssl) |
| 9174 | EXPECT_EQ(tests[i].expected_group_name, |
| 9175 | ssl_conn_pool->last_group_name_received()); |
| 9176 | else |
| 9177 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9178 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9179 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9180 | } |
| 9181 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9182 | TEST_P(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9183 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9184 | { |
| 9185 | "http_proxy", |
| 9186 | "http://www.example.org/http_proxy_normal", |
| 9187 | "www.example.org:80", |
| 9188 | false, |
| 9189 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9190 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9191 | // SSL Tests |
| 9192 | { |
| 9193 | "http_proxy", |
| 9194 | "https://www.example.org/http_connect_ssl", |
| 9195 | "ssl/www.example.org:443", |
| 9196 | true, |
| 9197 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 9198 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9199 | { |
| 9200 | "http_proxy", |
| 9201 | "http://host.with.alternate/direct", |
| 9202 | "ssl/host.with.alternate:443", |
| 9203 | true, |
| 9204 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 9205 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9206 | { |
| 9207 | "http_proxy", |
| 9208 | "ftp://ftp.google.com/http_proxy_normal", |
| 9209 | "ftp/ftp.google.com:21", |
| 9210 | false, |
| 9211 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9212 | }; |
| 9213 | |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 9214 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9215 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9216 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9217 | session_deps_.proxy_service = |
| 9218 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9219 | std::unique_ptr<HttpNetworkSession> session( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9220 | SetupSessionForGroupNameTests(GetProtocol(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9221 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9222 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9223 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9224 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9225 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9226 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9227 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9228 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9229 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9230 | std::unique_ptr<MockClientSocketPoolManager> mock_pool_manager( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 9231 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9232 | mock_pool_manager->SetSocketPoolForHTTPProxy(proxy_host, http_proxy_pool); |
| 9233 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9234 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9235 | |
| 9236 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9237 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9238 | if (tests[i].ssl) |
| 9239 | EXPECT_EQ(tests[i].expected_group_name, |
| 9240 | ssl_conn_pool->last_group_name_received()); |
| 9241 | else |
| 9242 | EXPECT_EQ(tests[i].expected_group_name, |
| 9243 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9244 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9245 | } |
| 9246 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9247 | TEST_P(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9248 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9249 | { |
| 9250 | "socks4://socks_proxy:1080", |
| 9251 | "http://www.example.org/socks4_direct", |
| 9252 | "socks4/www.example.org:80", |
| 9253 | false, |
| 9254 | }, |
| 9255 | { |
| 9256 | "socks5://socks_proxy:1080", |
| 9257 | "http://www.example.org/socks5_direct", |
| 9258 | "socks5/www.example.org:80", |
| 9259 | false, |
| 9260 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9261 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9262 | // SSL Tests |
| 9263 | { |
| 9264 | "socks4://socks_proxy:1080", |
| 9265 | "https://www.example.org/socks4_ssl", |
| 9266 | "socks4/ssl/www.example.org:443", |
| 9267 | true, |
| 9268 | }, |
| 9269 | { |
| 9270 | "socks5://socks_proxy:1080", |
| 9271 | "https://www.example.org/socks5_ssl", |
| 9272 | "socks5/ssl/www.example.org:443", |
| 9273 | true, |
| 9274 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 9275 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9276 | { |
| 9277 | "socks4://socks_proxy:1080", |
| 9278 | "http://host.with.alternate/direct", |
| 9279 | "socks4/ssl/host.with.alternate:443", |
| 9280 | true, |
| 9281 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9282 | }; |
| 9283 | |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 9284 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9285 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9286 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9287 | session_deps_.proxy_service = |
| 9288 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9289 | std::unique_ptr<HttpNetworkSession> session( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9290 | SetupSessionForGroupNameTests(GetProtocol(), &session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 9291 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9292 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9293 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9294 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9295 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9296 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9297 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9298 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9299 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9300 | std::unique_ptr<MockClientSocketPoolManager> mock_pool_manager( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 9301 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9302 | mock_pool_manager->SetSocketPoolForSOCKSProxy(proxy_host, socks_conn_pool); |
| 9303 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9304 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9305 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9306 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9307 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9308 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9309 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9310 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9311 | if (tests[i].ssl) |
| 9312 | EXPECT_EQ(tests[i].expected_group_name, |
| 9313 | ssl_conn_pool->last_group_name_received()); |
| 9314 | else |
| 9315 | EXPECT_EQ(tests[i].expected_group_name, |
| 9316 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9317 | } |
| 9318 | } |
| 9319 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9320 | TEST_P(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9321 | HttpRequestInfo request; |
| 9322 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9323 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9324 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9325 | session_deps_.proxy_service = |
| 9326 | ProxyService::CreateFixed("myproxy:70;foobar:80"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9327 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 9328 | // This simulates failure resolving all hostnames; that means we will fail |
| 9329 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9330 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9331 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9332 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9333 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9334 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9335 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9336 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9337 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9338 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9339 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9340 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9341 | rv = callback.WaitForResult(); |
[email protected] | f7fccee | 2010-09-16 20:53:01 | [diff] [blame] | 9342 | EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9343 | } |
| 9344 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9345 | // Base test to make sure that when the load flags for a request specify to |
| 9346 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9347 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9348 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9349 | // Issue a request, asking to bypass the cache(s). |
| 9350 | HttpRequestInfo request; |
| 9351 | request.method = "GET"; |
| 9352 | request.load_flags = load_flags; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9353 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9354 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 9355 | // Select a host resolver that does caching. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9356 | session_deps_.host_resolver.reset(new MockCachingHostResolver); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9357 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9358 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9359 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9360 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9361 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9362 | // 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] | 9363 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 9364 | TestCompletionCallback callback; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9365 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9366 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
| 9367 | DEFAULT_PRIORITY, &addrlist, callback.callback(), NULL, BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 9368 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9369 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9370 | EXPECT_EQ(OK, rv); |
| 9371 | |
| 9372 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 9373 | // and confirming it completes synchronously. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9374 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9375 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
| 9376 | DEFAULT_PRIORITY, &addrlist, callback.callback(), NULL, BoundNetLog()); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9377 | ASSERT_EQ(OK, rv); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9378 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9379 | // 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] | 9380 | // we can tell if the next lookup hit the cache, or the "network". |
| 9381 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9382 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9383 | |
| 9384 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 9385 | // 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] | 9386 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9387 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9388 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9389 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9390 | // Run the request. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9391 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9392 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9393 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9394 | |
| 9395 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9396 | // "www.example.org". |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9397 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
| 9398 | } |
| 9399 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9400 | // There are multiple load flags that should trigger the host cache bypass. |
| 9401 | // Test each in isolation: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9402 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9403 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 9404 | } |
| 9405 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9406 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9407 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 9408 | } |
| 9409 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9410 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9411 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 9412 | } |
| 9413 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9414 | // Make sure we can handle an error when writing the request. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9415 | TEST_P(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9416 | HttpRequestInfo request; |
| 9417 | request.method = "GET"; |
| 9418 | request.url = GURL("http://www.foo.com/"); |
| 9419 | request.load_flags = 0; |
| 9420 | |
| 9421 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9422 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9423 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9424 | StaticSocketDataProvider data(NULL, 0, |
| 9425 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9426 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9427 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9428 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9429 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9430 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9431 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9432 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9433 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9434 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9435 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9436 | |
| 9437 | rv = callback.WaitForResult(); |
| 9438 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9439 | |
| 9440 | IPEndPoint endpoint; |
| 9441 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 9442 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9443 | } |
| 9444 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9445 | // Check that a connection closed after the start of the headers finishes ok. |
| 9446 | TEST_P(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9447 | HttpRequestInfo request; |
| 9448 | request.method = "GET"; |
| 9449 | request.url = GURL("http://www.foo.com/"); |
| 9450 | request.load_flags = 0; |
| 9451 | |
| 9452 | MockRead data_reads[] = { |
| 9453 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9454 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9455 | }; |
| 9456 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9457 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9458 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9459 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9460 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9461 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9462 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9463 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9464 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9465 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9466 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9467 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9468 | |
| 9469 | rv = callback.WaitForResult(); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9470 | EXPECT_EQ(OK, rv); |
| 9471 | |
| 9472 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9473 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9474 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9475 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9476 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9477 | |
| 9478 | std::string response_data; |
| 9479 | rv = ReadTransaction(trans.get(), &response_data); |
| 9480 | EXPECT_EQ(OK, rv); |
| 9481 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9482 | |
| 9483 | IPEndPoint endpoint; |
| 9484 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 9485 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9486 | } |
| 9487 | |
| 9488 | // Make sure that a dropped connection while draining the body for auth |
| 9489 | // restart does the right thing. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9490 | TEST_P(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9491 | HttpRequestInfo request; |
| 9492 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9493 | request.url = GURL("http://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9494 | request.load_flags = 0; |
| 9495 | |
| 9496 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9497 | MockWrite( |
| 9498 | "GET / HTTP/1.1\r\n" |
| 9499 | "Host: www.example.org\r\n" |
| 9500 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9501 | }; |
| 9502 | |
| 9503 | MockRead data_reads1[] = { |
| 9504 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 9505 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9506 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9507 | MockRead("Content-Length: 14\r\n\r\n"), |
| 9508 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9509 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9510 | }; |
| 9511 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9512 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9513 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9514 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9515 | |
| 9516 | // After calling trans->RestartWithAuth(), this is the request we should |
| 9517 | // be issuing -- the final header line contains the credentials. |
| 9518 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9519 | MockWrite( |
| 9520 | "GET / HTTP/1.1\r\n" |
| 9521 | "Host: www.example.org\r\n" |
| 9522 | "Connection: keep-alive\r\n" |
| 9523 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9524 | }; |
| 9525 | |
| 9526 | // Lastly, the server responds with the actual content. |
| 9527 | MockRead data_reads2[] = { |
| 9528 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9529 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9530 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9531 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9532 | }; |
| 9533 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9534 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9535 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9536 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9537 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9538 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9539 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9540 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9541 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9542 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9543 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9544 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9545 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9546 | |
| 9547 | rv = callback1.WaitForResult(); |
| 9548 | EXPECT_EQ(OK, rv); |
| 9549 | |
| 9550 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9551 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9552 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9553 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9554 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9555 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9556 | rv = trans->RestartWithAuth( |
| 9557 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9558 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9559 | |
| 9560 | rv = callback2.WaitForResult(); |
| 9561 | EXPECT_EQ(OK, rv); |
| 9562 | |
| 9563 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9564 | ASSERT_TRUE(response); |
| 9565 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9566 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9567 | } |
| 9568 | |
| 9569 | // Test HTTPS connections going through a proxy that sends extra data. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9570 | TEST_P(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9571 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9572 | |
| 9573 | HttpRequestInfo request; |
| 9574 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9575 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9576 | request.load_flags = 0; |
| 9577 | |
| 9578 | MockRead proxy_reads[] = { |
| 9579 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9580 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9581 | }; |
| 9582 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9583 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9584 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9585 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9586 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9587 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9588 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9589 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9590 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9591 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9592 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9593 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9594 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9595 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9596 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9597 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9598 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9599 | |
| 9600 | rv = callback.WaitForResult(); |
| 9601 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 9602 | } |
| 9603 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9604 | TEST_P(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9605 | HttpRequestInfo request; |
| 9606 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9607 | request.url = GURL("http://www.example.org/"); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9608 | request.load_flags = 0; |
| 9609 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9610 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9611 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9612 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9613 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9614 | MockRead data_reads[] = { |
| 9615 | 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] | 9616 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9617 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9618 | |
| 9619 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9620 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9621 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9622 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9623 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9624 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9625 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9626 | |
| 9627 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9628 | |
| 9629 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9630 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9631 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9632 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9633 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9634 | |
| 9635 | std::string response_data; |
| 9636 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 5543cbb | 2012-04-20 16:35:23 | [diff] [blame] | 9637 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9638 | } |
| 9639 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9640 | TEST_P(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9641 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9642 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9643 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 9644 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 9645 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9646 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9647 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 9648 | element_readers.push_back(base::WrapUnique(new UploadFileElementReader( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9649 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
| 9650 | std::numeric_limits<uint64_t>::max(), base::Time()))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9651 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9652 | |
| 9653 | HttpRequestInfo request; |
| 9654 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9655 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9656 | request.upload_data_stream = &upload_data_stream; |
| 9657 | request.load_flags = 0; |
| 9658 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9659 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9660 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9661 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9662 | |
| 9663 | MockRead data_reads[] = { |
| 9664 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 9665 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9666 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9667 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9668 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9669 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9670 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9671 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9672 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9673 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9674 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9675 | |
| 9676 | rv = callback.WaitForResult(); |
| 9677 | EXPECT_EQ(OK, rv); |
| 9678 | |
| 9679 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9680 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9681 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9682 | EXPECT_TRUE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9683 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9684 | |
| 9685 | std::string response_data; |
| 9686 | rv = ReadTransaction(trans.get(), &response_data); |
| 9687 | EXPECT_EQ(OK, rv); |
| 9688 | EXPECT_EQ("hello world", response_data); |
| 9689 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9690 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9691 | } |
| 9692 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9693 | TEST_P(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9694 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9695 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9696 | std::string temp_file_content("Unreadable file."); |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 9697 | ASSERT_TRUE(base::WriteFile(temp_file, temp_file_content.c_str(), |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9698 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 9699 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9700 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9701 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 9702 | element_readers.push_back(base::WrapUnique(new UploadFileElementReader( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9703 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
| 9704 | std::numeric_limits<uint64_t>::max(), base::Time()))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9705 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9706 | |
| 9707 | HttpRequestInfo request; |
| 9708 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9709 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9710 | request.upload_data_stream = &upload_data_stream; |
| 9711 | request.load_flags = 0; |
| 9712 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9713 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9714 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9715 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9716 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9717 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9718 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9719 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9720 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9721 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9722 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9723 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9724 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9725 | |
| 9726 | rv = callback.WaitForResult(); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9727 | EXPECT_EQ(ERR_ACCESS_DENIED, rv); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9728 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9729 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9730 | } |
| 9731 | |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9732 | TEST_P(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
| 9733 | class FakeUploadElementReader : public UploadElementReader { |
| 9734 | public: |
| 9735 | FakeUploadElementReader() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9736 | ~FakeUploadElementReader() override {} |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9737 | |
| 9738 | const CompletionCallback& callback() const { return callback_; } |
| 9739 | |
| 9740 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9741 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9742 | callback_ = callback; |
| 9743 | return ERR_IO_PENDING; |
| 9744 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9745 | uint64_t GetContentLength() const override { return 0; } |
| 9746 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9747 | int Read(IOBuffer* buf, |
| 9748 | int buf_length, |
| 9749 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9750 | return ERR_FAILED; |
| 9751 | } |
| 9752 | |
| 9753 | private: |
| 9754 | CompletionCallback callback_; |
| 9755 | }; |
| 9756 | |
| 9757 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9758 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 9759 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9760 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9761 | |
| 9762 | HttpRequestInfo request; |
| 9763 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9764 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9765 | request.upload_data_stream = &upload_data_stream; |
| 9766 | request.load_flags = 0; |
| 9767 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9768 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9769 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9770 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9771 | |
| 9772 | StaticSocketDataProvider data; |
| 9773 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9774 | |
| 9775 | TestCompletionCallback callback; |
| 9776 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9777 | EXPECT_EQ(ERR_IO_PENDING, rv); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 9778 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9779 | |
| 9780 | // Transaction is pending on request body initialization. |
| 9781 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 9782 | |
| 9783 | // Return Init()'s result after the transaction gets destroyed. |
| 9784 | trans.reset(); |
| 9785 | fake_reader->callback().Run(OK); // Should not crash. |
| 9786 | } |
| 9787 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9788 | // Tests that changes to Auth realms are treated like auth rejections. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9789 | TEST_P(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9790 | HttpRequestInfo request; |
| 9791 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9792 | request.url = GURL("http://www.example.org/"); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9793 | request.load_flags = 0; |
| 9794 | |
| 9795 | // First transaction will request a resource and receive a Basic challenge |
| 9796 | // with realm="first_realm". |
| 9797 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9798 | MockWrite( |
| 9799 | "GET / HTTP/1.1\r\n" |
| 9800 | "Host: www.example.org\r\n" |
| 9801 | "Connection: keep-alive\r\n" |
| 9802 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9803 | }; |
| 9804 | MockRead data_reads1[] = { |
| 9805 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9806 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 9807 | "\r\n"), |
| 9808 | }; |
| 9809 | |
| 9810 | // After calling trans->RestartWithAuth(), provide an Authentication header |
| 9811 | // for first_realm. The server will reject and provide a challenge with |
| 9812 | // second_realm. |
| 9813 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9814 | MockWrite( |
| 9815 | "GET / HTTP/1.1\r\n" |
| 9816 | "Host: www.example.org\r\n" |
| 9817 | "Connection: keep-alive\r\n" |
| 9818 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 9819 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9820 | }; |
| 9821 | MockRead data_reads2[] = { |
| 9822 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9823 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 9824 | "\r\n"), |
| 9825 | }; |
| 9826 | |
| 9827 | // This again fails, and goes back to first_realm. Make sure that the |
| 9828 | // entry is removed from cache. |
| 9829 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9830 | MockWrite( |
| 9831 | "GET / HTTP/1.1\r\n" |
| 9832 | "Host: www.example.org\r\n" |
| 9833 | "Connection: keep-alive\r\n" |
| 9834 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 9835 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9836 | }; |
| 9837 | MockRead data_reads3[] = { |
| 9838 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9839 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 9840 | "\r\n"), |
| 9841 | }; |
| 9842 | |
| 9843 | // Try one last time (with the correct password) and get the resource. |
| 9844 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9845 | MockWrite( |
| 9846 | "GET / HTTP/1.1\r\n" |
| 9847 | "Host: www.example.org\r\n" |
| 9848 | "Connection: keep-alive\r\n" |
| 9849 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 9850 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9851 | }; |
| 9852 | MockRead data_reads4[] = { |
| 9853 | MockRead("HTTP/1.1 200 OK\r\n" |
| 9854 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9855 | "Content-Length: 5\r\n" |
| 9856 | "\r\n" |
| 9857 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9858 | }; |
| 9859 | |
| 9860 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9861 | data_writes1, arraysize(data_writes1)); |
| 9862 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9863 | data_writes2, arraysize(data_writes2)); |
| 9864 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 9865 | data_writes3, arraysize(data_writes3)); |
| 9866 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 9867 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9868 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9869 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 9870 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 9871 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9872 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9873 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9874 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9875 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9876 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9877 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9878 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9879 | // Issue the first request with Authorize headers. There should be a |
| 9880 | // password prompt for first_realm waiting to be filled in after the |
| 9881 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9882 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9883 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9884 | rv = callback1.WaitForResult(); |
| 9885 | EXPECT_EQ(OK, rv); |
| 9886 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9887 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9888 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9889 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9890 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9891 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9892 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 9893 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9894 | |
| 9895 | // Issue the second request with an incorrect password. There should be a |
| 9896 | // password prompt for second_realm waiting to be filled in after the |
| 9897 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9898 | TestCompletionCallback callback2; |
| 9899 | rv = trans->RestartWithAuth( |
| 9900 | AuthCredentials(kFirst, kBaz), callback2.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9901 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9902 | rv = callback2.WaitForResult(); |
| 9903 | EXPECT_EQ(OK, rv); |
| 9904 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9905 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9906 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9907 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9908 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9909 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9910 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 9911 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9912 | |
| 9913 | // Issue the third request with another incorrect password. There should be |
| 9914 | // a password prompt for first_realm waiting to be filled in. If the password |
| 9915 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 9916 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9917 | TestCompletionCallback callback3; |
| 9918 | rv = trans->RestartWithAuth( |
| 9919 | AuthCredentials(kSecond, kFou), callback3.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9920 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9921 | rv = callback3.WaitForResult(); |
| 9922 | EXPECT_EQ(OK, rv); |
| 9923 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9924 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9925 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9926 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9927 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9928 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9929 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 9930 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9931 | |
| 9932 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9933 | TestCompletionCallback callback4; |
| 9934 | rv = trans->RestartWithAuth( |
| 9935 | AuthCredentials(kFirst, kBar), callback4.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9936 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9937 | rv = callback4.WaitForResult(); |
| 9938 | EXPECT_EQ(OK, rv); |
| 9939 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9940 | ASSERT_TRUE(response); |
| 9941 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9942 | } |
| 9943 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9944 | TEST_P(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 9945 | session_deps_.enable_alternative_service_with_different_host = false; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9946 | |
| 9947 | std::string alternative_service_http_header = |
| 9948 | GetAlternativeServiceHttpHeader(); |
| 9949 | |
| 9950 | MockRead data_reads[] = { |
| 9951 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9952 | MockRead(alternative_service_http_header.c_str()), |
| 9953 | MockRead("\r\n"), |
| 9954 | MockRead("hello world"), |
| 9955 | MockRead(SYNCHRONOUS, OK), |
| 9956 | }; |
| 9957 | |
| 9958 | HttpRequestInfo request; |
| 9959 | request.method = "GET"; |
| 9960 | request.url = GURL("http://www.example.org/"); |
| 9961 | request.load_flags = 0; |
| 9962 | |
| 9963 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9964 | |
| 9965 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9966 | |
| 9967 | TestCompletionCallback callback; |
| 9968 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9969 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9970 | std::unique_ptr<HttpTransaction> trans( |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9971 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9972 | |
| 9973 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9974 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9975 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 9976 | url::SchemeHostPort test_server("http", "www.example.org", 80); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9977 | HttpServerProperties& http_server_properties = |
| 9978 | *session->http_server_properties(); |
| 9979 | AlternativeServiceVector alternative_service_vector = |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 9980 | http_server_properties.GetAlternativeServices(test_server); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9981 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9982 | |
| 9983 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9984 | |
| 9985 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9986 | ASSERT_TRUE(response); |
| 9987 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9988 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9989 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9990 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9991 | |
| 9992 | std::string response_data; |
| 9993 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9994 | EXPECT_EQ("hello world", response_data); |
| 9995 | |
| 9996 | alternative_service_vector = |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 9997 | http_server_properties.GetAlternativeServices(test_server); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9998 | ASSERT_EQ(1u, alternative_service_vector.size()); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9999 | EXPECT_EQ(AlternateProtocolFromNextProto(GetProtocol()), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10000 | alternative_service_vector[0].protocol); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10001 | EXPECT_EQ("www.example.org", alternative_service_vector[0].host); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10002 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 10003 | } |
| 10004 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10005 | // Regression test for https://crbug.com/615497. |
| 10006 | TEST_P(HttpNetworkTransactionTest, |
| 10007 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
| 10008 | session_deps_.enable_alternative_service_for_insecure_origins = false; |
| 10009 | |
| 10010 | std::string alternative_service_http_header = |
| 10011 | GetAlternativeServiceHttpHeader(); |
| 10012 | |
| 10013 | MockRead data_reads[] = { |
| 10014 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10015 | MockRead(alternative_service_http_header.c_str()), |
| 10016 | MockRead("\r\n"), |
| 10017 | MockRead("hello world"), |
| 10018 | MockRead(SYNCHRONOUS, OK), |
| 10019 | }; |
| 10020 | |
| 10021 | HttpRequestInfo request; |
| 10022 | request.method = "GET"; |
| 10023 | request.url = GURL("http://www.example.org/"); |
| 10024 | request.load_flags = 0; |
| 10025 | |
| 10026 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10027 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10028 | |
| 10029 | TestCompletionCallback callback; |
| 10030 | |
| 10031 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10032 | std::unique_ptr<HttpTransaction> trans( |
| 10033 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 10034 | |
| 10035 | url::SchemeHostPort test_server(request.url); |
| 10036 | HttpServerProperties& http_server_properties = |
| 10037 | *session->http_server_properties(); |
| 10038 | AlternativeServiceVector alternative_service_vector = |
| 10039 | http_server_properties.GetAlternativeServices(test_server); |
| 10040 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 10041 | |
| 10042 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10043 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10044 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10045 | |
| 10046 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10047 | ASSERT_TRUE(response); |
| 10048 | ASSERT_TRUE(response->headers); |
| 10049 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10050 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10051 | EXPECT_FALSE(response->was_npn_negotiated); |
| 10052 | |
| 10053 | std::string response_data; |
| 10054 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10055 | EXPECT_EQ("hello world", response_data); |
| 10056 | |
| 10057 | alternative_service_vector = |
| 10058 | http_server_properties.GetAlternativeServices(test_server); |
| 10059 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 10060 | } |
| 10061 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10062 | // HTTP/2 Alternative Services should be disabled if alternative service |
| 10063 | // hostname is different from that of origin. |
| 10064 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
| 10065 | TEST_P(HttpNetworkTransactionTest, |
| 10066 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
| 10067 | session_deps_.enable_alternative_service_with_different_host = true; |
| 10068 | |
| 10069 | HttpRequestInfo request; |
| 10070 | request.method = "GET"; |
| 10071 | request.url = GURL("http://www.example.org/"); |
| 10072 | request.load_flags = 0; |
| 10073 | |
| 10074 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10075 | StaticSocketDataProvider first_data; |
| 10076 | first_data.set_connect_data(mock_connect); |
| 10077 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 10078 | |
| 10079 | MockRead data_reads[] = { |
| 10080 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10081 | MockRead(ASYNC, OK), |
| 10082 | }; |
| 10083 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10084 | 0); |
| 10085 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10086 | |
| 10087 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10088 | |
| 10089 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 10090 | session->http_server_properties(); |
| 10091 | AlternativeService alternative_service( |
| 10092 | AlternateProtocolFromNextProto(GetProtocol()), "different.example.org", |
| 10093 | 444); |
| 10094 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10095 | http_server_properties->SetAlternativeService( |
| 10096 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10097 | |
| 10098 | std::unique_ptr<HttpTransaction> trans( |
| 10099 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 10100 | TestCompletionCallback callback; |
| 10101 | |
| 10102 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10103 | // Alternative service is not used, request fails. |
| 10104 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.GetResult(rv)); |
| 10105 | } |
| 10106 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10107 | // Regression test for https://crbug.com/615497: |
| 10108 | // Alternative Services should be disabled for http origin. |
| 10109 | TEST_P(HttpNetworkTransactionTest, |
| 10110 | DisableAlternativeServicesForInsecureOrigin) { |
| 10111 | session_deps_.enable_alternative_service_for_insecure_origins = false; |
| 10112 | |
| 10113 | HttpRequestInfo request; |
| 10114 | request.method = "GET"; |
| 10115 | request.url = GURL("http://www.example.org/"); |
| 10116 | request.load_flags = 0; |
| 10117 | |
| 10118 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10119 | StaticSocketDataProvider first_data; |
| 10120 | first_data.set_connect_data(mock_connect); |
| 10121 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 10122 | |
| 10123 | MockRead data_reads[] = { |
| 10124 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10125 | MockRead(ASYNC, OK), |
| 10126 | }; |
| 10127 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10128 | 0); |
| 10129 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10130 | |
| 10131 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10132 | |
| 10133 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 10134 | session->http_server_properties(); |
| 10135 | AlternativeService alternative_service( |
| 10136 | AlternateProtocolFromNextProto(GetProtocol()), "", 444); |
| 10137 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10138 | http_server_properties->SetAlternativeService( |
| 10139 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10140 | |
| 10141 | std::unique_ptr<HttpTransaction> trans( |
| 10142 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 10143 | TestCompletionCallback callback; |
| 10144 | |
| 10145 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10146 | // Alternative service is not used, request fails. |
| 10147 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.GetResult(rv)); |
| 10148 | } |
| 10149 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10150 | TEST_P(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10151 | session_deps_.enable_alternative_service_with_different_host = false; |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10152 | |
| 10153 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10154 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10155 | HttpServerProperties& http_server_properties = |
| 10156 | *session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10157 | url::SchemeHostPort test_server("http", "www.example.org", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10158 | AlternativeService alternative_service(QUIC, "", 80); |
| 10159 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10160 | http_server_properties.SetAlternativeService(test_server, alternative_service, |
| 10161 | expiration); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10162 | AlternativeServiceVector alternative_service_vector = |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10163 | http_server_properties.GetAlternativeServices(test_server); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10164 | EXPECT_EQ(1u, alternative_service_vector.size()); |
| 10165 | |
| 10166 | // Send a clear header. |
| 10167 | MockRead data_reads[] = { |
| 10168 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10169 | MockRead("Alt-Svc: clear\r\n"), |
| 10170 | MockRead("\r\n"), |
| 10171 | MockRead("hello world"), |
| 10172 | MockRead(SYNCHRONOUS, OK), |
| 10173 | }; |
| 10174 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 10175 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10176 | |
| 10177 | HttpRequestInfo request; |
| 10178 | request.method = "GET"; |
| 10179 | request.url = GURL("http://www.example.org/"); |
| 10180 | request.load_flags = 0; |
| 10181 | |
| 10182 | TestCompletionCallback callback; |
| 10183 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10184 | std::unique_ptr<HttpTransaction> trans( |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10185 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 10186 | |
| 10187 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10188 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 10189 | |
| 10190 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10191 | ASSERT_TRUE(response); |
| 10192 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10193 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10194 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10195 | EXPECT_FALSE(response->was_npn_negotiated); |
| 10196 | |
| 10197 | std::string response_data; |
| 10198 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10199 | EXPECT_EQ("hello world", response_data); |
| 10200 | |
| 10201 | alternative_service_vector = |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10202 | http_server_properties.GetAlternativeServices(test_server); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10203 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 10204 | } |
| 10205 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10206 | TEST_P(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeader) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10207 | session_deps_.enable_alternative_service_with_different_host = false; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10208 | |
| 10209 | MockRead data_reads[] = { |
| 10210 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10211 | MockRead("Alt-Svc: "), |
| 10212 | MockRead(GetAlternateProtocolFromParam()), |
bnc | 44858c8 | 2015-10-16 11:57:21 | [diff] [blame] | 10213 | MockRead("=\"www.example.com:443\";p=\"1.0\","), |
bnc | 3f0118e | 2016-02-02 15:42:22 | [diff] [blame] | 10214 | MockRead(GetAlternateProtocolFromParam()), |
| 10215 | MockRead("=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10216 | MockRead("hello world"), |
| 10217 | MockRead(SYNCHRONOUS, OK), |
| 10218 | }; |
| 10219 | |
| 10220 | HttpRequestInfo request; |
| 10221 | request.method = "GET"; |
| 10222 | request.url = GURL("http://www.example.org/"); |
| 10223 | request.load_flags = 0; |
| 10224 | |
| 10225 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10226 | |
| 10227 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10228 | |
| 10229 | TestCompletionCallback callback; |
| 10230 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10231 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10232 | std::unique_ptr<HttpTransaction> trans( |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10233 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 10234 | |
| 10235 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10236 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10237 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10238 | url::SchemeHostPort test_server("http", "www.example.org", 80); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10239 | HttpServerProperties& http_server_properties = |
| 10240 | *session->http_server_properties(); |
| 10241 | AlternativeServiceVector alternative_service_vector = |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10242 | http_server_properties.GetAlternativeServices(test_server); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10243 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 10244 | |
| 10245 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10246 | |
| 10247 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10248 | ASSERT_TRUE(response); |
| 10249 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10250 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10251 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10252 | EXPECT_FALSE(response->was_npn_negotiated); |
| 10253 | |
| 10254 | std::string response_data; |
| 10255 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10256 | EXPECT_EQ("hello world", response_data); |
| 10257 | |
| 10258 | alternative_service_vector = |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10259 | http_server_properties.GetAlternativeServices(test_server); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10260 | ASSERT_EQ(2u, alternative_service_vector.size()); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10261 | EXPECT_EQ(AlternateProtocolFromNextProto(GetProtocol()), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10262 | alternative_service_vector[0].protocol); |
| 10263 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 10264 | EXPECT_EQ(443, alternative_service_vector[0].port); |
bnc | 3f0118e | 2016-02-02 15:42:22 | [diff] [blame] | 10265 | EXPECT_EQ(AlternateProtocolFromNextProto(GetProtocol()), |
| 10266 | alternative_service_vector[1].protocol); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10267 | EXPECT_EQ("www.example.org", alternative_service_vector[1].host); |
| 10268 | EXPECT_EQ(1234, alternative_service_vector[1].port); |
| 10269 | } |
| 10270 | |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10271 | // When |enable_alternative_service_with_different_host| is false, do not |
| 10272 | // observe alternative service entries that point to a different host. |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 10273 | TEST_P(HttpNetworkTransactionTest, DisableAlternativeServiceToDifferentHost) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10274 | session_deps_.enable_alternative_service_with_different_host = false; |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 10275 | |
| 10276 | HttpRequestInfo request; |
| 10277 | request.method = "GET"; |
| 10278 | request.url = GURL("http://www.example.org/"); |
| 10279 | request.load_flags = 0; |
| 10280 | |
| 10281 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10282 | StaticSocketDataProvider first_data; |
| 10283 | first_data.set_connect_data(mock_connect); |
| 10284 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 10285 | |
| 10286 | MockRead data_reads[] = { |
| 10287 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10288 | MockRead(ASYNC, OK), |
| 10289 | }; |
| 10290 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), |
| 10291 | nullptr, 0); |
| 10292 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10293 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10294 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 10295 | |
| 10296 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 10297 | session->http_server_properties(); |
| 10298 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10299 | AlternateProtocolFromNextProto(GetProtocol()), "different.example.org", |
| 10300 | 80); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 10301 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10302 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10303 | url::SchemeHostPort(request.url), alternative_service, expiration); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 10304 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10305 | std::unique_ptr<HttpTransaction> trans( |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 10306 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 10307 | TestCompletionCallback callback; |
| 10308 | |
| 10309 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10310 | // The connetion to origin was refused, and the alternative service should not |
| 10311 | // be used (even though mock data are there), therefore the request should |
| 10312 | // fail. |
| 10313 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.GetResult(rv)); |
| 10314 | } |
| 10315 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10316 | TEST_P(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10317 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10318 | HostPortPair alternative("alternative.example.org", 443); |
| 10319 | std::string origin_url = "https://origin.example.org:443"; |
| 10320 | std::string alternative_url = "https://alternative.example.org:443"; |
| 10321 | |
| 10322 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 10323 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10324 | ssl.SetNextProto(kProtoHTTP11); |
| 10325 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10326 | |
| 10327 | // HTTP/1.1 data for request. |
| 10328 | MockWrite http_writes[] = { |
| 10329 | MockWrite("GET / HTTP/1.1\r\n" |
| 10330 | "Host: alternative.example.org\r\n" |
| 10331 | "Connection: keep-alive\r\n\r\n"), |
| 10332 | }; |
| 10333 | |
| 10334 | MockRead http_reads[] = { |
| 10335 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10336 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10337 | "Content-Length: 40\r\n\r\n" |
| 10338 | "first HTTP/1.1 response from alternative"), |
| 10339 | }; |
| 10340 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10341 | http_writes, arraysize(http_writes)); |
| 10342 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10343 | |
| 10344 | StaticSocketDataProvider data_refused; |
| 10345 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10346 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10347 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10348 | // Set up a QUIC alternative service for server. |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10349 | session_deps_.enable_alternative_service_with_different_host = false; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10350 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10351 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 10352 | session->http_server_properties(); |
| 10353 | AlternativeService alternative_service(QUIC, alternative); |
| 10354 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10355 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10356 | expiration); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10357 | // Mark the QUIC alternative service as broken. |
| 10358 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 10359 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10360 | std::unique_ptr<HttpTransaction> trans( |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10361 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 10362 | HttpRequestInfo request; |
| 10363 | request.method = "GET"; |
| 10364 | request.url = GURL(origin_url); |
| 10365 | request.load_flags = 0; |
| 10366 | TestCompletionCallback callback; |
| 10367 | NetErrorDetails details; |
| 10368 | EXPECT_FALSE(details.quic_broken); |
| 10369 | |
| 10370 | trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10371 | trans->PopulateNetErrorDetails(&details); |
| 10372 | EXPECT_TRUE(details.quic_broken); |
| 10373 | } |
| 10374 | |
| 10375 | TEST_P(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10376 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10377 | HostPortPair alternative1("alternative1.example.org", 443); |
| 10378 | HostPortPair alternative2("alternative2.example.org", 443); |
| 10379 | std::string origin_url = "https://origin.example.org:443"; |
| 10380 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 10381 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 10382 | |
| 10383 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 10384 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10385 | ssl.SetNextProto(kProtoHTTP11); |
| 10386 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10387 | |
| 10388 | // HTTP/1.1 data for request. |
| 10389 | MockWrite http_writes[] = { |
| 10390 | MockWrite("GET / HTTP/1.1\r\n" |
| 10391 | "Host: alternative1.example.org\r\n" |
| 10392 | "Connection: keep-alive\r\n\r\n"), |
| 10393 | }; |
| 10394 | |
| 10395 | MockRead http_reads[] = { |
| 10396 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10397 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10398 | "Content-Length: 40\r\n\r\n" |
| 10399 | "first HTTP/1.1 response from alternative1"), |
| 10400 | }; |
| 10401 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10402 | http_writes, arraysize(http_writes)); |
| 10403 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10404 | |
| 10405 | StaticSocketDataProvider data_refused; |
| 10406 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10407 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10408 | |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10409 | session_deps_.enable_alternative_service_with_different_host = true; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10410 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10411 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 10412 | session->http_server_properties(); |
| 10413 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10414 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10415 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 10416 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10417 | |
| 10418 | AlternativeService alternative_service1(QUIC, alternative1); |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10419 | AlternativeServiceInfo alternative_service_info1(alternative_service1, |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10420 | expiration); |
| 10421 | alternative_service_info_vector.push_back(alternative_service_info1); |
| 10422 | AlternativeService alternative_service2(QUIC, alternative2); |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10423 | AlternativeServiceInfo alternative_service_info2(alternative_service2, |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10424 | expiration); |
| 10425 | alternative_service_info_vector.push_back(alternative_service_info2); |
| 10426 | |
| 10427 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10428 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10429 | |
| 10430 | // Mark one of the QUIC alternative service as broken. |
| 10431 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
| 10432 | |
| 10433 | const AlternativeServiceVector alternative_service_vector = |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10434 | http_server_properties->GetAlternativeServices(server); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10435 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10436 | std::unique_ptr<HttpTransaction> trans( |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10437 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 10438 | HttpRequestInfo request; |
| 10439 | request.method = "GET"; |
| 10440 | request.url = GURL(origin_url); |
| 10441 | request.load_flags = 0; |
| 10442 | TestCompletionCallback callback; |
| 10443 | NetErrorDetails details; |
| 10444 | EXPECT_FALSE(details.quic_broken); |
| 10445 | |
| 10446 | trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10447 | trans->PopulateNetErrorDetails(&details); |
| 10448 | EXPECT_FALSE(details.quic_broken); |
| 10449 | } |
| 10450 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10451 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10452 | MarkBrokenAlternateProtocolAndFallback) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10453 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10454 | |
| 10455 | HttpRequestInfo request; |
| 10456 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10457 | request.url = GURL("http://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10458 | request.load_flags = 0; |
| 10459 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10460 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10461 | StaticSocketDataProvider first_data; |
| 10462 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10463 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10464 | |
| 10465 | MockRead data_reads[] = { |
| 10466 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10467 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10468 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10469 | }; |
| 10470 | StaticSocketDataProvider second_data( |
| 10471 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10472 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10473 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10474 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10475 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10476 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10477 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10478 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10479 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 10480 | // port 80 (another restricted port). |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10481 | const AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10482 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10483 | 666); // Port is ignored by MockConnect anyway. |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10484 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10485 | http_server_properties->SetAlternativeService(server, alternative_service, |
| 10486 | expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10487 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10488 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10489 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10490 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10491 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10492 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10493 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10494 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10495 | |
| 10496 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10497 | ASSERT_TRUE(response); |
| 10498 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10499 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10500 | |
| 10501 | std::string response_data; |
| 10502 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10503 | EXPECT_EQ("hello world", response_data); |
| 10504 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10505 | const AlternativeServiceVector alternative_service_vector = |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10506 | http_server_properties->GetAlternativeServices(server); |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10507 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 10508 | EXPECT_EQ(alternative_service, alternative_service_vector[0]); |
| 10509 | EXPECT_TRUE(http_server_properties->IsAlternativeServiceBroken( |
| 10510 | alternative_service_vector[0])); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10511 | } |
| 10512 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10513 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10514 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10515 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10516 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10517 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10518 | AlternateProtocolPortRestrictedBlocked) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10519 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10520 | |
| 10521 | HttpRequestInfo restricted_port_request; |
| 10522 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10523 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10524 | restricted_port_request.load_flags = 0; |
| 10525 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10526 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10527 | StaticSocketDataProvider first_data; |
| 10528 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10529 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10530 | |
| 10531 | MockRead data_reads[] = { |
| 10532 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10533 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10534 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10535 | }; |
| 10536 | StaticSocketDataProvider second_data( |
| 10537 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10538 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10539 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10540 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10541 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10542 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10543 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10544 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10545 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10546 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10547 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10548 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10549 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10550 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10551 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10552 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10553 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10554 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10555 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10556 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10557 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10558 | &restricted_port_request, |
| 10559 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10560 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10561 | // Invalid change to unrestricted port should fail. |
| 10562 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10563 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10564 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10565 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 10566 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 10567 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10568 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10569 | AlternateProtocolPortRestrictedPermitted) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10570 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10571 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10572 | |
| 10573 | HttpRequestInfo restricted_port_request; |
| 10574 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10575 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10576 | restricted_port_request.load_flags = 0; |
| 10577 | |
| 10578 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10579 | StaticSocketDataProvider first_data; |
| 10580 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10581 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10582 | |
| 10583 | MockRead data_reads[] = { |
| 10584 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10585 | MockRead("hello world"), |
| 10586 | MockRead(ASYNC, OK), |
| 10587 | }; |
| 10588 | StaticSocketDataProvider second_data( |
| 10589 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10590 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10591 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10592 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10593 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10594 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10595 | session->http_server_properties(); |
| 10596 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10597 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10598 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10599 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10600 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10601 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10602 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10603 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10604 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10605 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10606 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10607 | TestCompletionCallback callback; |
| 10608 | |
| 10609 | EXPECT_EQ(ERR_IO_PENDING, trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10610 | &restricted_port_request, |
| 10611 | callback.callback(), BoundNetLog())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10612 | // Change to unrestricted port should succeed. |
| 10613 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10614 | } |
| 10615 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10616 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10617 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10618 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10619 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10620 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10621 | AlternateProtocolPortRestrictedAllowed) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10622 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10623 | |
| 10624 | HttpRequestInfo restricted_port_request; |
| 10625 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10626 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10627 | restricted_port_request.load_flags = 0; |
| 10628 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10629 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10630 | StaticSocketDataProvider first_data; |
| 10631 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10632 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10633 | |
| 10634 | MockRead data_reads[] = { |
| 10635 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10636 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10637 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10638 | }; |
| 10639 | StaticSocketDataProvider second_data( |
| 10640 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10641 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10642 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10643 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10644 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10645 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10646 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10647 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10648 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10649 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10650 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10651 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10652 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10653 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10654 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10655 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10656 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10657 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10658 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10659 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10660 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10661 | &restricted_port_request, |
| 10662 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10663 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10664 | // Valid change to restricted port should pass. |
| 10665 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10666 | } |
| 10667 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10668 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10669 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10670 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10671 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10672 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10673 | AlternateProtocolPortUnrestrictedAllowed1) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10674 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10675 | |
| 10676 | HttpRequestInfo unrestricted_port_request; |
| 10677 | unrestricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10678 | unrestricted_port_request.url = GURL("http://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10679 | unrestricted_port_request.load_flags = 0; |
| 10680 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10681 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10682 | StaticSocketDataProvider first_data; |
| 10683 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10684 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10685 | |
| 10686 | MockRead data_reads[] = { |
| 10687 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10688 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10689 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10690 | }; |
| 10691 | StaticSocketDataProvider second_data( |
| 10692 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10693 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10694 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10695 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10696 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10697 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10698 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10699 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10700 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10701 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10702 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10703 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10704 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10705 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10706 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10707 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10708 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10709 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10710 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10711 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10712 | int rv = trans->Start( |
| 10713 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10714 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10715 | // Valid change to restricted port should pass. |
| 10716 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10717 | } |
| 10718 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10719 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10720 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10721 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10722 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10723 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10724 | AlternateProtocolPortUnrestrictedAllowed2) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10725 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10726 | |
| 10727 | HttpRequestInfo unrestricted_port_request; |
| 10728 | unrestricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10729 | unrestricted_port_request.url = GURL("http://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10730 | unrestricted_port_request.load_flags = 0; |
| 10731 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10732 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10733 | StaticSocketDataProvider first_data; |
| 10734 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10735 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10736 | |
| 10737 | MockRead data_reads[] = { |
| 10738 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10739 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10740 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10741 | }; |
| 10742 | StaticSocketDataProvider second_data( |
| 10743 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10744 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10745 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10746 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10747 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10748 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10749 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 10750 | const int kUnrestrictedAlternatePort = 1025; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10751 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10752 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10753 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10754 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10755 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10756 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10757 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10758 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10759 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10760 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10761 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10762 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10763 | int rv = trans->Start( |
| 10764 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10765 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10766 | // Valid change to an unrestricted port should pass. |
| 10767 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10768 | } |
| 10769 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10770 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10771 | // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job |
| 10772 | // once the alternate protocol request fails. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10773 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 10774 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10775 | |
| 10776 | HttpRequestInfo request; |
| 10777 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10778 | request.url = GURL("http://www.example.org/"); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10779 | request.load_flags = 0; |
| 10780 | |
| 10781 | // The alternate protocol request will error out before we attempt to connect, |
| 10782 | // so only the standard HTTP request will try to connect. |
| 10783 | MockRead data_reads[] = { |
| 10784 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10785 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10786 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10787 | }; |
| 10788 | StaticSocketDataProvider data( |
| 10789 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10790 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10791 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10792 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10793 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10794 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10795 | session->http_server_properties(); |
| 10796 | const int kUnsafePort = 7; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10797 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10798 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10799 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10800 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10801 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10802 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10803 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10804 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10805 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10806 | TestCompletionCallback callback; |
| 10807 | |
| 10808 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10809 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10810 | // The HTTP request should succeed. |
| 10811 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10812 | |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10813 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10814 | ASSERT_TRUE(response); |
| 10815 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10816 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10817 | |
| 10818 | std::string response_data; |
| 10819 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10820 | EXPECT_EQ("hello world", response_data); |
| 10821 | } |
| 10822 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10823 | TEST_P(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 10824 | session_deps_.enable_alternative_service_with_different_host = true; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10825 | |
| 10826 | HttpRequestInfo request; |
| 10827 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10828 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10829 | request.load_flags = 0; |
| 10830 | |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 10831 | std::string alternative_service_http_header = |
| 10832 | GetAlternativeServiceHttpHeader(); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10833 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10834 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10835 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 10836 | MockRead(alternative_service_http_header.c_str()), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10837 | MockRead("\r\n"), |
| 10838 | MockRead("hello world"), |
| 10839 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10840 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10841 | |
| 10842 | StaticSocketDataProvider first_transaction( |
| 10843 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10844 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10845 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10846 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10847 | ssl.SetNextProto(GetProtocol()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10848 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10849 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10850 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10851 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10852 | std::unique_ptr<SpdySerializedFrame> req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 10853 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10854 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10855 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10856 | std::unique_ptr<SpdySerializedFrame> resp( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 10857 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10858 | std::unique_ptr<SpdySerializedFrame> data( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 10859 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10860 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10861 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10862 | }; |
| 10863 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10864 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10865 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10866 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10867 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10868 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10869 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10870 | NULL, 0, NULL, 0); |
| 10871 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10872 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10873 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10874 | &hanging_non_alternate_protocol_socket); |
| 10875 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10876 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10877 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10878 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10879 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10880 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10881 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10882 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10883 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10884 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10885 | |
| 10886 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10887 | ASSERT_TRUE(response); |
| 10888 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10889 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10890 | |
| 10891 | std::string response_data; |
| 10892 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10893 | EXPECT_EQ("hello world", response_data); |
| 10894 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10895 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10896 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10897 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10898 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10899 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10900 | |
| 10901 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10902 | ASSERT_TRUE(response); |
| 10903 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 10904 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10905 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10906 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10907 | |
| 10908 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10909 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10910 | } |
| 10911 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10912 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 10913 | session_deps_.enable_alternative_service_with_different_host = true; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10914 | |
| 10915 | HttpRequestInfo request; |
| 10916 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10917 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10918 | request.load_flags = 0; |
| 10919 | |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 10920 | std::string alternative_service_http_header = |
| 10921 | GetAlternativeServiceHttpHeader(); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10922 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10923 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10924 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 10925 | MockRead(alternative_service_http_header.c_str()), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10926 | MockRead("\r\n"), |
| 10927 | MockRead("hello world"), |
| 10928 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10929 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10930 | }; |
| 10931 | |
| 10932 | StaticSocketDataProvider first_transaction( |
| 10933 | data_reads, arraysize(data_reads), NULL, 0); |
| 10934 | // Socket 1 is the HTTP transaction with the Alternate-Protocol header. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10935 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10936 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10937 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10938 | StaticSocketDataProvider hanging_socket1(NULL, 0, NULL, 0); |
| 10939 | hanging_socket1.set_connect_data(never_finishing_connect); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10940 | // Socket 2 and 3 are the hanging Alternate-Protocol and |
| 10941 | // non-Alternate-Protocol jobs from the 2nd transaction. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10942 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 10943 | |
| 10944 | StaticSocketDataProvider hanging_socket2(NULL, 0, NULL, 0); |
| 10945 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 10946 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10947 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10948 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10949 | ssl.SetNextProto(GetProtocol()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10950 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10951 | ASSERT_TRUE(ssl.cert); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10952 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10953 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10954 | std::unique_ptr<SpdySerializedFrame> req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 10955 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10956 | std::unique_ptr<SpdySerializedFrame> req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 10957 | spdy_util_.ConstructSpdyGet(nullptr, 0, 3, LOWEST, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10958 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10959 | CreateMockWrite(*req1, 0), CreateMockWrite(*req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10960 | }; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10961 | std::unique_ptr<SpdySerializedFrame> resp1( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 10962 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10963 | std::unique_ptr<SpdySerializedFrame> data1( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 10964 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10965 | std::unique_ptr<SpdySerializedFrame> resp2( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 10966 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10967 | std::unique_ptr<SpdySerializedFrame> data2( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 10968 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10969 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10970 | CreateMockRead(*resp1, 2), |
| 10971 | CreateMockRead(*data1, 3), |
| 10972 | CreateMockRead(*resp2, 4), |
| 10973 | CreateMockRead(*data2, 5), |
| 10974 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10975 | }; |
| 10976 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10977 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10978 | arraysize(spdy_writes)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10979 | // Socket 4 is the successful Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10980 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10981 | |
| 10982 | // Socket 5 is the unsuccessful non-Alternate-Protocol for transaction 3. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10983 | StaticSocketDataProvider hanging_socket3(NULL, 0, NULL, 0); |
| 10984 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 10985 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10986 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10987 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10988 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10989 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10990 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10991 | int rv = trans1.Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10992 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10993 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 10994 | |
| 10995 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10996 | ASSERT_TRUE(response); |
| 10997 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10998 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10999 | |
| 11000 | std::string response_data; |
| 11001 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 11002 | EXPECT_EQ("hello world", response_data); |
| 11003 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11004 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11005 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11006 | rv = trans2.Start(&request, callback2.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11007 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11008 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11009 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11010 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11011 | rv = trans3.Start(&request, callback3.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11012 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11013 | |
| 11014 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 11015 | EXPECT_EQ(OK, callback3.WaitForResult()); |
| 11016 | |
| 11017 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11018 | ASSERT_TRUE(response); |
| 11019 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11020 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11021 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11022 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11023 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 11024 | EXPECT_EQ("hello!", response_data); |
| 11025 | |
| 11026 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11027 | ASSERT_TRUE(response); |
| 11028 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11029 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11030 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11031 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11032 | ASSERT_EQ(OK, ReadTransaction(&trans3, &response_data)); |
| 11033 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11034 | } |
| 11035 | |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 11036 | TEST_P(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
| 11037 | session_deps_.enable_alternative_service_with_different_host = true; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11038 | |
| 11039 | HttpRequestInfo request; |
| 11040 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11041 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11042 | request.load_flags = 0; |
| 11043 | |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 11044 | std::string alternative_service_http_header = |
| 11045 | GetAlternativeServiceHttpHeader(); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 11046 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11047 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11048 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 11049 | MockRead(alternative_service_http_header.c_str()), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11050 | MockRead("\r\n"), |
| 11051 | MockRead("hello world"), |
| 11052 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11053 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11054 | }; |
| 11055 | |
| 11056 | StaticSocketDataProvider first_transaction( |
| 11057 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11058 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11059 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11060 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 11061 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11062 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [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_alternate_protocol_socket( |
| 11066 | NULL, 0, NULL, 0); |
| 11067 | hanging_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_alternate_protocol_socket); |
| 11071 | |
| 11072 | // 2nd request is just a copy of the first one, over HTTP again. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11073 | StaticSocketDataProvider second_transaction(data_reads, arraysize(data_reads), |
| 11074 | NULL, 0); |
| 11075 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11076 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11077 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11078 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11079 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11080 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11081 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11082 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11083 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11084 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11085 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11086 | |
| 11087 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11088 | ASSERT_TRUE(response); |
| 11089 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11090 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11091 | |
| 11092 | std::string response_data; |
| 11093 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11094 | EXPECT_EQ("hello world", response_data); |
| 11095 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11096 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11097 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11098 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11099 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11100 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11101 | |
| 11102 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11103 | ASSERT_TRUE(response); |
| 11104 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11105 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11106 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 11107 | EXPECT_FALSE(response->was_npn_negotiated); |
| 11108 | |
| 11109 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11110 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11111 | } |
| 11112 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11113 | class CapturingProxyResolver : public ProxyResolver { |
| 11114 | public: |
sammc | e90c921 | 2015-05-27 23:43:35 | [diff] [blame] | 11115 | CapturingProxyResolver() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11116 | ~CapturingProxyResolver() override {} |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11117 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11118 | int GetProxyForURL(const GURL& url, |
| 11119 | ProxyInfo* results, |
| 11120 | const CompletionCallback& callback, |
eroman | 9c8f424 | 2016-02-29 21:16:54 | [diff] [blame] | 11121 | RequestHandle* request, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11122 | const BoundNetLog& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 11123 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 11124 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11125 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11126 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11127 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11128 | } |
| 11129 | |
eroman | 9c8f424 | 2016-02-29 21:16:54 | [diff] [blame] | 11130 | void CancelRequest(RequestHandle request) override { NOTREACHED(); } |
| 11131 | |
| 11132 | LoadState GetLoadState(RequestHandle request) const override { |
| 11133 | NOTREACHED(); |
| 11134 | return LOAD_STATE_IDLE; |
| 11135 | } |
| 11136 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 11137 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 11138 | |
| 11139 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11140 | std::vector<GURL> resolved_; |
| 11141 | |
| 11142 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 11143 | }; |
| 11144 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11145 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 11146 | public: |
| 11147 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 11148 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 11149 | |
| 11150 | int CreateProxyResolver( |
| 11151 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11152 | std::unique_ptr<ProxyResolver>* resolver, |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11153 | const net::CompletionCallback& callback, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11154 | std::unique_ptr<Request>* request) override { |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11155 | resolver->reset(new ForwardingProxyResolver(resolver_)); |
| 11156 | return OK; |
| 11157 | } |
| 11158 | |
| 11159 | private: |
| 11160 | ProxyResolver* resolver_; |
| 11161 | }; |
| 11162 | |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 11163 | TEST_P(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
| 11164 | session_deps_.enable_alternative_service_with_different_host = true; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11165 | |
| 11166 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11167 | proxy_config.set_auto_detect(true); |
| 11168 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 11169 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11170 | CapturingProxyResolver capturing_proxy_resolver; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11171 | session_deps_.proxy_service.reset(new ProxyService( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11172 | base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
| 11173 | base::WrapUnique( |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11174 | new CapturingProxyResolverFactory(&capturing_proxy_resolver)), |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 11175 | NULL)); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11176 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11177 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11178 | |
| 11179 | HttpRequestInfo request; |
| 11180 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11181 | request.url = GURL("http://www.example.org/"); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11182 | request.load_flags = 0; |
| 11183 | |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 11184 | std::string alternative_service_http_header = |
| 11185 | GetAlternativeServiceHttpHeader(); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 11186 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11187 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11188 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 11189 | MockRead(alternative_service_http_header.c_str()), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11190 | MockRead("\r\n"), |
| 11191 | MockRead("hello world"), |
| 11192 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11193 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11194 | }; |
| 11195 | |
| 11196 | StaticSocketDataProvider first_transaction( |
| 11197 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11198 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11199 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11200 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 11201 | ssl.SetNextProto(GetProtocol()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11202 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11203 | ASSERT_TRUE(ssl.cert); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11204 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11205 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11206 | std::unique_ptr<SpdySerializedFrame> req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 11207 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11208 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11209 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11210 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11211 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11212 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 11213 | CreateMockWrite(*req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11214 | }; |
| 11215 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11216 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 11217 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11218 | std::unique_ptr<SpdySerializedFrame> resp( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 11219 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11220 | std::unique_ptr<SpdySerializedFrame> data( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 11221 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11222 | MockRead spdy_reads[] = { |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 11223 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(*resp.get(), 3), |
| 11224 | CreateMockRead(*data.get(), 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11225 | }; |
| 11226 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11227 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11228 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11229 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11230 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11231 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11232 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11233 | NULL, 0, NULL, 0); |
| 11234 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11235 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11236 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11237 | &hanging_non_alternate_protocol_socket); |
| 11238 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11239 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11240 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11241 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11242 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11243 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11244 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11245 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11246 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11247 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11248 | |
| 11249 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11250 | ASSERT_TRUE(response); |
| 11251 | ASSERT_TRUE(response->headers); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11252 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11253 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 11254 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11255 | |
| 11256 | std::string response_data; |
| 11257 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11258 | EXPECT_EQ("hello world", response_data); |
| 11259 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11260 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11261 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11262 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11263 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11264 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11265 | |
| 11266 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11267 | ASSERT_TRUE(response); |
| 11268 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11269 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11270 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11271 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11272 | |
| 11273 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11274 | EXPECT_EQ("hello!", response_data); |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11275 | ASSERT_EQ(3u, capturing_proxy_resolver.resolved().size()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11276 | EXPECT_EQ("http://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11277 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11278 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11279 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11280 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11281 | LoadTimingInfo load_timing_info; |
| 11282 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11283 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11284 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11285 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11286 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11287 | TEST_P(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 11288 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
| 11289 | session_deps_.enable_alternative_service_with_different_host = true; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11290 | |
| 11291 | HttpRequestInfo request; |
| 11292 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11293 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11294 | request.load_flags = 0; |
| 11295 | |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 11296 | std::string alternative_service_http_header = |
| 11297 | GetAlternativeServiceHttpHeader(); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 11298 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11299 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11300 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 11301 | MockRead(alternative_service_http_header.c_str()), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11302 | MockRead("\r\n"), |
| 11303 | MockRead("hello world"), |
| 11304 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11305 | }; |
| 11306 | |
| 11307 | StaticSocketDataProvider first_transaction( |
| 11308 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11309 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11310 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11311 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 11312 | ssl.SetNextProto(GetProtocol()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11313 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11314 | ASSERT_TRUE(ssl.cert); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11315 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11316 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11317 | std::unique_ptr<SpdySerializedFrame> req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 11318 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11319 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11320 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11321 | std::unique_ptr<SpdySerializedFrame> resp( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 11322 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11323 | std::unique_ptr<SpdySerializedFrame> data( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 11324 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11325 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11326 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11327 | }; |
| 11328 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11329 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11330 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11331 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11332 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 11333 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11334 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11335 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11336 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11337 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11338 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11339 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11340 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11341 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11342 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11343 | |
| 11344 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11345 | ASSERT_TRUE(response); |
| 11346 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11347 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11348 | |
| 11349 | std::string response_data; |
| 11350 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11351 | EXPECT_EQ("hello world", response_data); |
| 11352 | |
| 11353 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11354 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11355 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 11356 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11357 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11358 | CreateSecureSpdySession(session.get(), key, BoundNetLog()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 11359 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11360 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11361 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11362 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11363 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11364 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11365 | |
| 11366 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11367 | ASSERT_TRUE(response); |
| 11368 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11369 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11370 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11371 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11372 | |
| 11373 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11374 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11375 | } |
| 11376 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11377 | // GenerateAuthToken is a mighty big test. |
| 11378 | // It tests all permutation of GenerateAuthToken behavior: |
| 11379 | // - Synchronous and Asynchronous completion. |
| 11380 | // - OK or error on completion. |
| 11381 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 11382 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 11383 | // - Non-authenticating and authenticating backend. |
| 11384 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 11385 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11386 | // problems generating an auth token for an authenticating proxy, we don't |
| 11387 | // need to test all permutations of the backend server). |
| 11388 | // |
| 11389 | // The test proceeds by going over each of the configuration cases, and |
| 11390 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 11391 | // specifies both the configuration for the test as well as the expectations |
| 11392 | // for the results. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11393 | TEST_P(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11394 | static const char kServer[] = "http://www.example.com"; |
| 11395 | static const char kSecureServer[] = "https://www.example.com"; |
| 11396 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11397 | const int kAuthErr = ERR_INVALID_AUTH_CREDENTIALS; |
| 11398 | |
| 11399 | enum AuthTiming { |
| 11400 | AUTH_NONE, |
| 11401 | AUTH_SYNC, |
| 11402 | AUTH_ASYNC, |
| 11403 | }; |
| 11404 | |
| 11405 | const MockWrite kGet( |
| 11406 | "GET / HTTP/1.1\r\n" |
| 11407 | "Host: www.example.com\r\n" |
| 11408 | "Connection: keep-alive\r\n\r\n"); |
| 11409 | const MockWrite kGetProxy( |
| 11410 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11411 | "Host: www.example.com\r\n" |
| 11412 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11413 | const MockWrite kGetAuth( |
| 11414 | "GET / HTTP/1.1\r\n" |
| 11415 | "Host: www.example.com\r\n" |
| 11416 | "Connection: keep-alive\r\n" |
| 11417 | "Authorization: auth_token\r\n\r\n"); |
| 11418 | const MockWrite kGetProxyAuth( |
| 11419 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11420 | "Host: www.example.com\r\n" |
| 11421 | "Proxy-Connection: keep-alive\r\n" |
| 11422 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11423 | const MockWrite kGetAuthThroughProxy( |
| 11424 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11425 | "Host: www.example.com\r\n" |
| 11426 | "Proxy-Connection: keep-alive\r\n" |
| 11427 | "Authorization: auth_token\r\n\r\n"); |
| 11428 | const MockWrite kGetAuthWithProxyAuth( |
| 11429 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11430 | "Host: www.example.com\r\n" |
| 11431 | "Proxy-Connection: keep-alive\r\n" |
| 11432 | "Proxy-Authorization: auth_token\r\n" |
| 11433 | "Authorization: auth_token\r\n\r\n"); |
| 11434 | const MockWrite kConnect( |
| 11435 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11436 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11437 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11438 | const MockWrite kConnectProxyAuth( |
| 11439 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11440 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11441 | "Proxy-Connection: keep-alive\r\n" |
| 11442 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11443 | |
| 11444 | const MockRead kSuccess( |
| 11445 | "HTTP/1.1 200 OK\r\n" |
| 11446 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11447 | "Content-Length: 3\r\n\r\n" |
| 11448 | "Yes"); |
| 11449 | const MockRead kFailure( |
| 11450 | "Should not be called."); |
| 11451 | const MockRead kServerChallenge( |
| 11452 | "HTTP/1.1 401 Unauthorized\r\n" |
| 11453 | "WWW-Authenticate: Mock realm=server\r\n" |
| 11454 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11455 | "Content-Length: 14\r\n\r\n" |
| 11456 | "Unauthorized\r\n"); |
| 11457 | const MockRead kProxyChallenge( |
| 11458 | "HTTP/1.1 407 Unauthorized\r\n" |
| 11459 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 11460 | "Proxy-Connection: close\r\n" |
| 11461 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11462 | "Content-Length: 14\r\n\r\n" |
| 11463 | "Unauthorized\r\n"); |
| 11464 | const MockRead kProxyConnected( |
| 11465 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 11466 | |
| 11467 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 11468 | // no constructors, but the C++ compiler on Windows warns about |
| 11469 | // unspecified data in compound literals. So, moved to using constructors, |
| 11470 | // and TestRound's created with the default constructor should not be used. |
| 11471 | struct TestRound { |
| 11472 | TestRound() |
| 11473 | : expected_rv(ERR_UNEXPECTED), |
| 11474 | extra_write(NULL), |
| 11475 | extra_read(NULL) { |
| 11476 | } |
| 11477 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11478 | int expected_rv_arg) |
| 11479 | : write(write_arg), |
| 11480 | read(read_arg), |
| 11481 | expected_rv(expected_rv_arg), |
| 11482 | extra_write(NULL), |
| 11483 | extra_read(NULL) { |
| 11484 | } |
| 11485 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11486 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 11487 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11488 | : write(write_arg), |
| 11489 | read(read_arg), |
| 11490 | expected_rv(expected_rv_arg), |
| 11491 | extra_write(extra_write_arg), |
| 11492 | extra_read(extra_read_arg) { |
| 11493 | } |
| 11494 | MockWrite write; |
| 11495 | MockRead read; |
| 11496 | int expected_rv; |
| 11497 | const MockWrite* extra_write; |
| 11498 | const MockRead* extra_read; |
| 11499 | }; |
| 11500 | |
| 11501 | static const int kNoSSL = 500; |
| 11502 | |
| 11503 | struct TestConfig { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11504 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11505 | AuthTiming proxy_auth_timing; |
| 11506 | int proxy_auth_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11507 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11508 | AuthTiming server_auth_timing; |
| 11509 | int server_auth_rv; |
| 11510 | int num_auth_rounds; |
| 11511 | int first_ssl_round; |
| 11512 | TestRound rounds[3]; |
| 11513 | } test_configs[] = { |
| 11514 | // Non-authenticating HTTP server with a direct connection. |
| 11515 | { NULL, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 11516 | { TestRound(kGet, kSuccess, OK)}}, |
| 11517 | // Authenticating HTTP server with a direct connection. |
| 11518 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 11519 | { TestRound(kGet, kServerChallenge, OK), |
| 11520 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11521 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 11522 | { TestRound(kGet, kServerChallenge, OK), |
| 11523 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11524 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 11525 | { TestRound(kGet, kServerChallenge, OK), |
| 11526 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11527 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 11528 | { TestRound(kGet, kServerChallenge, OK), |
| 11529 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11530 | // Non-authenticating HTTP server through a non-authenticating proxy. |
| 11531 | { kProxy, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 11532 | { TestRound(kGetProxy, kSuccess, OK)}}, |
| 11533 | // Authenticating HTTP server through a non-authenticating proxy. |
| 11534 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 11535 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 11536 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 11537 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 11538 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 11539 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 11540 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 11541 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 11542 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 11543 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 11544 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 11545 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 11546 | // Non-authenticating HTTP server through an authenticating proxy. |
| 11547 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11548 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11549 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 11550 | { kProxy, AUTH_SYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11551 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11552 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 11553 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11554 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11555 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 11556 | { kProxy, AUTH_ASYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11557 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11558 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 11559 | // Authenticating HTTP server through an authenticating proxy. |
| 11560 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 11561 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11562 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11563 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11564 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 11565 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11566 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11567 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11568 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 11569 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11570 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11571 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11572 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 11573 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11574 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11575 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11576 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 11577 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11578 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11579 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11580 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 11581 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11582 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11583 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11584 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 11585 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11586 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11587 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11588 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 11589 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11590 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11591 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11592 | // Non-authenticating HTTPS server with a direct connection. |
| 11593 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 11594 | { TestRound(kGet, kSuccess, OK)}}, |
| 11595 | // Authenticating HTTPS server with a direct connection. |
| 11596 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 11597 | { TestRound(kGet, kServerChallenge, OK), |
| 11598 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11599 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 11600 | { TestRound(kGet, kServerChallenge, OK), |
| 11601 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11602 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 11603 | { TestRound(kGet, kServerChallenge, OK), |
| 11604 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11605 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 11606 | { TestRound(kGet, kServerChallenge, OK), |
| 11607 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11608 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
| 11609 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 11610 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11611 | // Authenticating HTTPS server through a non-authenticating proxy. |
| 11612 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 11613 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11614 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11615 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 11616 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11617 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11618 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 11619 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11620 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11621 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 11622 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11623 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11624 | // Non-Authenticating HTTPS server through an authenticating proxy. |
| 11625 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 11626 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11627 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11628 | { kProxy, AUTH_SYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11629 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11630 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 11631 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 11632 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11633 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11634 | { kProxy, AUTH_ASYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11635 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11636 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 11637 | // Authenticating HTTPS server through an authenticating proxy. |
| 11638 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 11639 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11640 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11641 | &kGet, &kServerChallenge), |
| 11642 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11643 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 11644 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11645 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11646 | &kGet, &kServerChallenge), |
| 11647 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11648 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 11649 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11650 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11651 | &kGet, &kServerChallenge), |
| 11652 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11653 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 11654 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11655 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11656 | &kGet, &kServerChallenge), |
| 11657 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11658 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 11659 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11660 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11661 | &kGet, &kServerChallenge), |
| 11662 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11663 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 11664 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11665 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11666 | &kGet, &kServerChallenge), |
| 11667 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11668 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 11669 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11670 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11671 | &kGet, &kServerChallenge), |
| 11672 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11673 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 11674 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11675 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11676 | &kGet, &kServerChallenge), |
| 11677 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11678 | }; |
| 11679 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 11680 | for (size_t i = 0; i < arraysize(test_configs); ++i) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11681 | HttpAuthHandlerMock::Factory* auth_factory( |
| 11682 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11683 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 11684 | SSLInfo empty_ssl_info; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11685 | const TestConfig& test_config = test_configs[i]; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 11686 | |
| 11687 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11688 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11689 | for (int n = 0; n < 2; n++) { |
| 11690 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 11691 | std::string auth_challenge = "Mock realm=proxy"; |
| 11692 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 11693 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 11694 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11695 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 11696 | empty_ssl_info, origin, BoundNetLog()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11697 | auth_handler->SetGenerateExpectation( |
| 11698 | test_config.proxy_auth_timing == AUTH_ASYNC, |
| 11699 | test_config.proxy_auth_rv); |
| 11700 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 11701 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11702 | } |
| 11703 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 11704 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11705 | std::string auth_challenge = "Mock realm=server"; |
| 11706 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 11707 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 11708 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11709 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 11710 | empty_ssl_info, origin, BoundNetLog()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11711 | auth_handler->SetGenerateExpectation( |
| 11712 | test_config.server_auth_timing == AUTH_ASYNC, |
| 11713 | test_config.server_auth_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11714 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11715 | } |
| 11716 | if (test_config.proxy_url) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11717 | session_deps_.proxy_service = |
| 11718 | ProxyService::CreateFixed(test_config.proxy_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11719 | } else { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11720 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11721 | } |
| 11722 | |
| 11723 | HttpRequestInfo request; |
| 11724 | request.method = "GET"; |
| 11725 | request.url = GURL(test_config.server_url); |
| 11726 | request.load_flags = 0; |
| 11727 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11728 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11729 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11730 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 11731 | |
| 11732 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 11733 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11734 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 11735 | const TestRound& read_write_round = test_config.rounds[round]; |
| 11736 | |
| 11737 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11738 | mock_reads.back().push_back(read_write_round.read); |
| 11739 | mock_writes.back().push_back(read_write_round.write); |
| 11740 | |
| 11741 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 11742 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 11743 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11744 | mock_reads.push_back(std::vector<MockRead>()); |
| 11745 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11746 | } |
| 11747 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11748 | if (read_write_round.extra_read) { |
| 11749 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11750 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11751 | if (read_write_round.extra_write) { |
| 11752 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 11753 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11754 | |
| 11755 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11756 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11757 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11758 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11759 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11760 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11761 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11762 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11763 | data_providers.push_back(base::WrapUnique(new StaticSocketDataProvider( |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 11764 | mock_reads[i].data(), mock_reads[i].size(), mock_writes[i].data(), |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 11765 | mock_writes[i].size()))); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11766 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 11767 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11768 | } |
| 11769 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11770 | // Transaction must be created after DataProviders, so it's destroyed before |
| 11771 | // they are as well. |
| 11772 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11773 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11774 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 11775 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11776 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11777 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11778 | int rv; |
| 11779 | if (round == 0) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11780 | rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11781 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11782 | rv = trans.RestartWithAuth( |
| 11783 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11784 | } |
| 11785 | if (rv == ERR_IO_PENDING) |
| 11786 | rv = callback.WaitForResult(); |
| 11787 | |
| 11788 | // Compare results with expected data. |
| 11789 | EXPECT_EQ(read_write_round.expected_rv, rv); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11790 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 11791 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11792 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 11793 | continue; |
| 11794 | } |
| 11795 | if (round + 1 < test_config.num_auth_rounds) { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11796 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11797 | } else { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11798 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11799 | } |
| 11800 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 11801 | } |
| 11802 | } |
| 11803 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11804 | TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11805 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11806 | HttpAuthHandlerMock::Factory* auth_factory( |
| 11807 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11808 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11809 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11810 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 11811 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11812 | |
| 11813 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 11814 | auth_handler->set_connection_based(true); |
| 11815 | std::string auth_challenge = "Mock realm=server"; |
| 11816 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 11817 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 11818 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 11819 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11820 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 11821 | empty_ssl_info, origin, BoundNetLog()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11822 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11823 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11824 | int rv = OK; |
| 11825 | const HttpResponseInfo* response = NULL; |
| 11826 | HttpRequestInfo request; |
| 11827 | request.method = "GET"; |
| 11828 | request.url = origin; |
| 11829 | request.load_flags = 0; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11830 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11831 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11832 | |
| 11833 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 11834 | // to validate that the TCP socket is not released to the pool between |
| 11835 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11836 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11837 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11838 | 50, // Max sockets for pool |
| 11839 | 1, // Max sockets per group |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 11840 | session_deps_.host_resolver.get(), session_deps_.socket_factory.get(), |
| 11841 | NULL, session_deps_.net_log); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11842 | std::unique_ptr<MockClientSocketPoolManager> mock_pool_manager( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 11843 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 11844 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11845 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11846 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11847 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11848 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11849 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11850 | |
| 11851 | const MockWrite kGet( |
| 11852 | "GET / HTTP/1.1\r\n" |
| 11853 | "Host: www.example.com\r\n" |
| 11854 | "Connection: keep-alive\r\n\r\n"); |
| 11855 | const MockWrite kGetAuth( |
| 11856 | "GET / HTTP/1.1\r\n" |
| 11857 | "Host: www.example.com\r\n" |
| 11858 | "Connection: keep-alive\r\n" |
| 11859 | "Authorization: auth_token\r\n\r\n"); |
| 11860 | |
| 11861 | const MockRead kServerChallenge( |
| 11862 | "HTTP/1.1 401 Unauthorized\r\n" |
| 11863 | "WWW-Authenticate: Mock realm=server\r\n" |
| 11864 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11865 | "Content-Length: 14\r\n\r\n" |
| 11866 | "Unauthorized\r\n"); |
| 11867 | const MockRead kSuccess( |
| 11868 | "HTTP/1.1 200 OK\r\n" |
| 11869 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11870 | "Content-Length: 3\r\n\r\n" |
| 11871 | "Yes"); |
| 11872 | |
| 11873 | MockWrite writes[] = { |
| 11874 | // First round |
| 11875 | kGet, |
| 11876 | // Second round |
| 11877 | kGetAuth, |
| 11878 | // Third round |
| 11879 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11880 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11881 | kGetAuth, |
| 11882 | // Competing request |
| 11883 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11884 | }; |
| 11885 | MockRead reads[] = { |
| 11886 | // First round |
| 11887 | kServerChallenge, |
| 11888 | // Second round |
| 11889 | kServerChallenge, |
| 11890 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11891 | kServerChallenge, |
| 11892 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11893 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11894 | // Competing response |
| 11895 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11896 | }; |
| 11897 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 11898 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11899 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11900 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11901 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11902 | |
| 11903 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11904 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11905 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11906 | if (rv == ERR_IO_PENDING) |
| 11907 | rv = callback.WaitForResult(); |
| 11908 | EXPECT_EQ(OK, rv); |
| 11909 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11910 | ASSERT_TRUE(response); |
| 11911 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11912 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11913 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11914 | // In between rounds, another request comes in for the same domain. |
| 11915 | // It should not be able to grab the TCP socket that trans has already |
| 11916 | // claimed. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11917 | std::unique_ptr<HttpTransaction> trans_compete( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11918 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11919 | TestCompletionCallback callback_compete; |
| 11920 | rv = trans_compete->Start( |
| 11921 | &request, callback_compete.callback(), BoundNetLog()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11922 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11923 | // callback_compete.WaitForResult at this point would stall forever, |
| 11924 | // since the HttpNetworkTransaction does not release the request back to |
| 11925 | // the pool until after authentication completes. |
| 11926 | |
| 11927 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11928 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11929 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11930 | if (rv == ERR_IO_PENDING) |
| 11931 | rv = callback.WaitForResult(); |
| 11932 | EXPECT_EQ(OK, rv); |
| 11933 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11934 | ASSERT_TRUE(response); |
| 11935 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11936 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11937 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11938 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11939 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11940 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11941 | if (rv == ERR_IO_PENDING) |
| 11942 | rv = callback.WaitForResult(); |
| 11943 | EXPECT_EQ(OK, rv); |
| 11944 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11945 | ASSERT_TRUE(response); |
| 11946 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11947 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11948 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11949 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11950 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11951 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11952 | if (rv == ERR_IO_PENDING) |
| 11953 | rv = callback.WaitForResult(); |
| 11954 | EXPECT_EQ(OK, rv); |
| 11955 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11956 | ASSERT_TRUE(response); |
| 11957 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11958 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11959 | |
| 11960 | // Read the body since the fourth round was successful. This will also |
| 11961 | // release the socket back to the pool. |
| 11962 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11963 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11964 | if (rv == ERR_IO_PENDING) |
| 11965 | rv = callback.WaitForResult(); |
| 11966 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11967 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11968 | EXPECT_EQ(0, rv); |
| 11969 | // There are still 0 idle sockets, since the trans_compete transaction |
| 11970 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11971 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11972 | |
| 11973 | // The competing request can now finish. Wait for the headers and then |
| 11974 | // read the body. |
| 11975 | rv = callback_compete.WaitForResult(); |
| 11976 | EXPECT_EQ(OK, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11977 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11978 | if (rv == ERR_IO_PENDING) |
| 11979 | rv = callback.WaitForResult(); |
| 11980 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11981 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11982 | EXPECT_EQ(0, rv); |
| 11983 | |
| 11984 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11985 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11986 | } |
| 11987 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11988 | // This tests the case that a request is issued via http instead of spdy after |
| 11989 | // npn is negotiated. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11990 | TEST_P(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 11991 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11992 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11993 | HttpRequestInfo request; |
| 11994 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11995 | request.url = GURL("https://www.example.org/"); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11996 | request.load_flags = 0; |
| 11997 | |
| 11998 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11999 | MockWrite( |
| 12000 | "GET / HTTP/1.1\r\n" |
| 12001 | "Host: www.example.org\r\n" |
| 12002 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12003 | }; |
| 12004 | |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 12005 | std::string alternative_service_http_header = |
| 12006 | GetAlternativeServiceHttpHeader(); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 12007 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12008 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12009 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 12010 | MockRead(alternative_service_http_header.c_str()), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12011 | MockRead("\r\n"), |
| 12012 | MockRead("hello world"), |
| 12013 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12014 | }; |
| 12015 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12016 | SSLSocketDataProvider ssl(ASYNC, OK); |
davidben | 6974bf7 | 2015-04-27 17:52:48 | [diff] [blame] | 12017 | ssl.SetNextProto(kProtoHTTP11); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12018 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12019 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12020 | |
| 12021 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12022 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12023 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12024 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12025 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12026 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12027 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12028 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12029 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12030 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12031 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12032 | |
| 12033 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12034 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 12035 | |
| 12036 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12037 | ASSERT_TRUE(response); |
| 12038 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12039 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12040 | |
| 12041 | std::string response_data; |
| 12042 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 12043 | EXPECT_EQ("hello world", response_data); |
| 12044 | |
| 12045 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 12046 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12047 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12048 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12049 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 12050 | // immediate server closing of the socket. |
| 12051 | // Regression test for https://crbug.com/46369. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12052 | TEST_P(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 12053 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12054 | |
| 12055 | HttpRequestInfo request; |
| 12056 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12057 | request.url = GURL("https://www.example.org/"); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12058 | request.load_flags = 0; |
| 12059 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12060 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12061 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12062 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12063 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12064 | std::unique_ptr<SpdySerializedFrame> req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12065 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12066 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12067 | |
| 12068 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12069 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12070 | }; |
| 12071 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12072 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12073 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12074 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12075 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12076 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12077 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12078 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12079 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12080 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12081 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12082 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12083 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12084 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12085 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 12086 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12087 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 12088 | // it gets it. This is needed since the auth handler may get destroyed |
| 12089 | // before we get a chance to query it. |
| 12090 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 12091 | public: |
| 12092 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 12093 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12094 | ~UrlRecordingHttpAuthHandlerMock() override {} |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12095 | |
| 12096 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12097 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 12098 | const HttpRequestInfo* request, |
| 12099 | const CompletionCallback& callback, |
| 12100 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12101 | *url_ = request->url; |
| 12102 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 12103 | credentials, request, callback, auth_token); |
| 12104 | } |
| 12105 | |
| 12106 | private: |
| 12107 | GURL* url_; |
| 12108 | }; |
| 12109 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12110 | // This test ensures that the URL passed into the proxy is upgraded to https |
| 12111 | // when doing an Alternate Protocol upgrade. |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 12112 | TEST_P(HttpNetworkTransactionTest, SpdyAlternativeServiceThroughProxy) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 12113 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12114 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12115 | session_deps_.proxy_service = |
| 12116 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12117 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12118 | session_deps_.net_log = &net_log; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12119 | GURL request_url; |
| 12120 | { |
| 12121 | HttpAuthHandlerMock::Factory* auth_factory = |
| 12122 | new HttpAuthHandlerMock::Factory(); |
| 12123 | UrlRecordingHttpAuthHandlerMock* auth_handler = |
| 12124 | new UrlRecordingHttpAuthHandlerMock(&request_url); |
| 12125 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 12126 | auth_factory->set_do_init_from_challenge(true); |
| 12127 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
| 12128 | } |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12129 | |
| 12130 | HttpRequestInfo request; |
| 12131 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12132 | request.url = GURL("http://www.example.org"); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12133 | request.load_flags = 0; |
| 12134 | |
| 12135 | // First round goes unauthenticated through the proxy. |
| 12136 | MockWrite data_writes_1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12137 | MockWrite( |
| 12138 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 12139 | "Host: www.example.org\r\n" |
| 12140 | "Proxy-Connection: keep-alive\r\n" |
| 12141 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12142 | }; |
| 12143 | MockRead data_reads_1[] = { |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 12144 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12145 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12146 | MockRead("Alt-Svc: "), |
| 12147 | MockRead(GetAlternateProtocolFromParam()), |
| 12148 | MockRead("=\":443\"\r\n"), |
| 12149 | MockRead("Proxy-Connection: close\r\n"), |
| 12150 | MockRead("\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12151 | }; |
| 12152 | StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1), |
| 12153 | data_writes_1, arraysize(data_writes_1)); |
| 12154 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12155 | // Second round tries to tunnel to www.example.org due to the |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12156 | // Alternate-Protocol announcement in the first round. It fails due |
| 12157 | // to a proxy authentication challenge. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12158 | // After the failure, a tunnel is established to www.example.org using |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 12159 | // Proxy-Authorization headers. There is then a SPDY request round. |
| 12160 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 12161 | // NOTE: Despite the "Proxy-Connection: Close", these are done on the |
| 12162 | // same MockTCPClientSocket since the underlying HttpNetworkClientSocket |
| 12163 | // does a Disconnect and Connect on the same socket, rather than trying |
| 12164 | // to obtain a new one. |
| 12165 | // |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 12166 | // NOTE: Originally, the proxy response to the second CONNECT request |
| 12167 | // simply returned another 407 so the unit test could skip the SSL connection |
| 12168 | // establishment and SPDY framing issues. Alas, the |
| 12169 | // retry-http-when-alternate-protocol fails logic kicks in, which was more |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12170 | // complicated to set up expectations for than the SPDY session. |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 12171 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12172 | std::unique_ptr<SpdySerializedFrame> req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12173 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12174 | std::unique_ptr<SpdySerializedFrame> resp( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 12175 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12176 | std::unique_ptr<SpdySerializedFrame> data( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 12177 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12178 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 12179 | MockWrite data_writes_2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12180 | // First connection attempt without Proxy-Authorization. |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12181 | MockWrite(ASYNC, 0, |
| 12182 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12183 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12184 | "Proxy-Connection: keep-alive\r\n" |
| 12185 | "\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 12186 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12187 | // Second connection attempt with Proxy-Authorization. |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12188 | MockWrite(ASYNC, 2, |
| 12189 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12190 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12191 | "Proxy-Connection: keep-alive\r\n" |
| 12192 | "Proxy-Authorization: auth_token\r\n" |
| 12193 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12194 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12195 | // SPDY request |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12196 | CreateMockWrite(*req, 4), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12197 | }; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 12198 | MockRead data_reads_2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12199 | // First connection attempt fails |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 12200 | MockRead(ASYNC, 1, |
| 12201 | "HTTP/1.1 407 Unauthorized\r\n" |
| 12202 | "Proxy-Authenticate: Mock\r\n" |
| 12203 | "Content-Length: 0\r\n" |
| 12204 | "Proxy-Connection: keep-alive\r\n" |
| 12205 | "\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 12206 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12207 | // Second connection attempt passes |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 12208 | MockRead(ASYNC, 3, "HTTP/1.1 200 Connected\r\n\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 12209 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12210 | // SPDY response |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 12211 | CreateMockRead(*resp.get(), 5), CreateMockRead(*data.get(), 6), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12212 | MockRead(ASYNC, 0, 0, 7), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 12213 | }; |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12214 | SequencedSocketData data_2(data_reads_2, arraysize(data_reads_2), |
| 12215 | data_writes_2, arraysize(data_writes_2)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12216 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12217 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12218 | ssl.SetNextProto(GetProtocol()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12219 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12220 | ASSERT_TRUE(ssl.cert); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12221 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12222 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12223 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 12224 | NULL, 0, NULL, 0); |
| 12225 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 12226 | never_finishing_connect); |
| 12227 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12228 | session_deps_.socket_factory->AddSocketDataProvider(&data_1); |
| 12229 | session_deps_.socket_factory->AddSocketDataProvider(&data_2); |
| 12230 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12231 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12232 | &hanging_non_alternate_protocol_socket); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12233 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12234 | |
| 12235 | // First round should work and provide the Alternate-Protocol state. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12236 | TestCompletionCallback callback_1; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12237 | std::unique_ptr<HttpTransaction> trans_1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12238 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12239 | int rv = trans_1->Start(&request, callback_1.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12240 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12241 | EXPECT_EQ(OK, callback_1.WaitForResult()); |
| 12242 | |
| 12243 | // Second round should attempt a tunnel connect and get an auth challenge. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12244 | TestCompletionCallback callback_2; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12245 | std::unique_ptr<HttpTransaction> trans_2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12246 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12247 | rv = trans_2->Start(&request, callback_2.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12248 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12249 | EXPECT_EQ(OK, callback_2.WaitForResult()); |
| 12250 | const HttpResponseInfo* response = trans_2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12251 | ASSERT_TRUE(response); |
| 12252 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12253 | |
| 12254 | // Restart with auth. Tunnel should work and response received. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12255 | TestCompletionCallback callback_3; |
| 12256 | rv = trans_2->RestartWithAuth( |
| 12257 | AuthCredentials(kFoo, kBar), callback_3.callback()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12258 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12259 | EXPECT_EQ(OK, callback_3.WaitForResult()); |
| 12260 | |
| 12261 | // After all that work, these two lines (or actually, just the scheme) are |
| 12262 | // what this test is all about. Make sure it happens correctly. |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12263 | EXPECT_EQ("https", request_url.scheme()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12264 | EXPECT_EQ("www.example.org", request_url.host()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12265 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12266 | LoadTimingInfo load_timing_info; |
| 12267 | EXPECT_TRUE(trans_2->GetLoadTimingInfo(&load_timing_info)); |
| 12268 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12269 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12270 | } |
| 12271 | |
| 12272 | // Test that if we cancel the transaction as the connection is completing, that |
| 12273 | // everything tears down correctly. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12274 | TEST_P(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12275 | // Setup everything about the connection to complete synchronously, so that |
| 12276 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 12277 | // for is the callback from the HttpStreamRequest. |
| 12278 | // Then cancel the transaction. |
| 12279 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12280 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12281 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12282 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 12283 | MockRead(SYNCHRONOUS, "hello world"), |
| 12284 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12285 | }; |
| 12286 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12287 | HttpRequestInfo request; |
| 12288 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12289 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12290 | request.load_flags = 0; |
| 12291 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12292 | session_deps_.host_resolver->set_synchronous_mode(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12293 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12294 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12295 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12296 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12297 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 12298 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12299 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12300 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12301 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12302 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12303 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12304 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12305 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12306 | trans.reset(); // Cancel the transaction here. |
| 12307 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 12308 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12309 | } |
| 12310 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12311 | // Test that if a transaction is cancelled after receiving the headers, the |
| 12312 | // stream is drained properly and added back to the socket pool. The main |
| 12313 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 12314 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 12315 | // deleted. |
| 12316 | // See http://crbug.com/368418 |
| 12317 | TEST_P(HttpNetworkTransactionTest, CancelAfterHeaders) { |
| 12318 | MockRead data_reads[] = { |
| 12319 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 12320 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 12321 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 12322 | MockRead(ASYNC, "1"), |
| 12323 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 12324 | // HttpNetworkTransaction has been deleted. |
| 12325 | MockRead(ASYNC, "2"), |
| 12326 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 12327 | }; |
| 12328 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 12329 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12330 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12331 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12332 | |
| 12333 | { |
| 12334 | HttpRequestInfo request; |
| 12335 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12336 | request.url = GURL("http://www.example.org/"); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12337 | request.load_flags = 0; |
| 12338 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12339 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12340 | TestCompletionCallback callback; |
| 12341 | |
| 12342 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
| 12343 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12344 | callback.WaitForResult(); |
| 12345 | |
| 12346 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12347 | ASSERT_TRUE(response); |
| 12348 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12349 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12350 | |
| 12351 | // The transaction and HttpRequestInfo are deleted. |
| 12352 | } |
| 12353 | |
| 12354 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 12355 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12356 | |
| 12357 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12358 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12359 | } |
| 12360 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12361 | // Test a basic GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12362 | TEST_P(HttpNetworkTransactionTest, ProxyGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12363 | session_deps_.proxy_service = |
| 12364 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12365 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12366 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12367 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12368 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12369 | HttpRequestInfo request; |
| 12370 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12371 | request.url = GURL("http://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12372 | |
| 12373 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12374 | MockWrite( |
| 12375 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 12376 | "Host: www.example.org\r\n" |
| 12377 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12378 | }; |
| 12379 | |
| 12380 | MockRead data_reads1[] = { |
| 12381 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12382 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12383 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12384 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12385 | }; |
| 12386 | |
| 12387 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12388 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12389 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12390 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12391 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12392 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12393 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12394 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame^] | 12395 | BeforeHeadersSentHandler headers_handler; |
| 12396 | trans->SetBeforeHeadersSentCallback( |
| 12397 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 12398 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12399 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12400 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12401 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12402 | |
| 12403 | rv = callback1.WaitForResult(); |
| 12404 | EXPECT_EQ(OK, rv); |
| 12405 | |
| 12406 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12407 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12408 | |
| 12409 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12410 | EXPECT_EQ(200, response->headers->response_code()); |
| 12411 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12412 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 12413 | EXPECT_TRUE( |
| 12414 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame^] | 12415 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 12416 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 12417 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12418 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12419 | |
| 12420 | LoadTimingInfo load_timing_info; |
| 12421 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 12422 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12423 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12424 | } |
| 12425 | |
| 12426 | // Test a basic HTTPS GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12427 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12428 | session_deps_.proxy_service = |
| 12429 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12430 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12431 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12432 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12433 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12434 | HttpRequestInfo request; |
| 12435 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12436 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12437 | |
| 12438 | // Since we have proxy, should try to establish tunnel. |
| 12439 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12440 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12441 | "Host: www.example.org:443\r\n" |
| 12442 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12443 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12444 | MockWrite("GET / HTTP/1.1\r\n" |
| 12445 | "Host: www.example.org\r\n" |
| 12446 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12447 | }; |
| 12448 | |
| 12449 | MockRead data_reads1[] = { |
| 12450 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 12451 | |
| 12452 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12453 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12454 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12455 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12456 | }; |
| 12457 | |
| 12458 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12459 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12460 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12461 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12462 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12463 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12464 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12465 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12466 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12467 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame^] | 12468 | BeforeHeadersSentHandler headers_handler; |
| 12469 | trans->SetBeforeHeadersSentCallback( |
| 12470 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 12471 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12472 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12473 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12474 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12475 | |
| 12476 | rv = callback1.WaitForResult(); |
| 12477 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 12478 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12479 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12480 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12481 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12482 | NetLog::PHASE_NONE); |
| 12483 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12484 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12485 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12486 | NetLog::PHASE_NONE); |
| 12487 | |
| 12488 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12489 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12490 | |
| 12491 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12492 | EXPECT_EQ(200, response->headers->response_code()); |
| 12493 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12494 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 12495 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 12496 | EXPECT_TRUE( |
| 12497 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame^] | 12498 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 12499 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 12500 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12501 | |
| 12502 | LoadTimingInfo load_timing_info; |
| 12503 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 12504 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12505 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12506 | } |
| 12507 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12508 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 12509 | // literal host. |
| 12510 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
| 12511 | session_deps_.proxy_service = |
| 12512 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 12513 | BoundTestNetLog log; |
| 12514 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12515 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12516 | |
| 12517 | HttpRequestInfo request; |
| 12518 | request.method = "GET"; |
| 12519 | request.url = GURL("https://[::1]:443/"); |
| 12520 | |
| 12521 | // Since we have proxy, should try to establish tunnel. |
| 12522 | MockWrite data_writes1[] = { |
| 12523 | MockWrite("CONNECT [::1]:443 HTTP/1.1\r\n" |
| 12524 | "Host: [::1]:443\r\n" |
| 12525 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 12526 | |
| 12527 | MockWrite("GET / HTTP/1.1\r\n" |
| 12528 | "Host: [::1]\r\n" |
| 12529 | "Connection: keep-alive\r\n\r\n"), |
| 12530 | }; |
| 12531 | |
| 12532 | MockRead data_reads1[] = { |
| 12533 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 12534 | |
| 12535 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12536 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12537 | MockRead("Content-Length: 100\r\n\r\n"), |
| 12538 | MockRead(SYNCHRONOUS, OK), |
| 12539 | }; |
| 12540 | |
| 12541 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12542 | data_writes1, arraysize(data_writes1)); |
| 12543 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 12544 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12545 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12546 | |
| 12547 | TestCompletionCallback callback1; |
| 12548 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12549 | std::unique_ptr<HttpTransaction> trans( |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12550 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12551 | |
| 12552 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 12553 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12554 | |
| 12555 | rv = callback1.WaitForResult(); |
| 12556 | EXPECT_EQ(OK, rv); |
| 12557 | TestNetLogEntry::List entries; |
| 12558 | log.GetEntries(&entries); |
| 12559 | size_t pos = ExpectLogContainsSomewhere( |
| 12560 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 12561 | NetLog::PHASE_NONE); |
| 12562 | ExpectLogContainsSomewhere( |
| 12563 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12564 | NetLog::PHASE_NONE); |
| 12565 | |
| 12566 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12567 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12568 | |
| 12569 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12570 | EXPECT_EQ(200, response->headers->response_code()); |
| 12571 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12572 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 12573 | EXPECT_TRUE(response->was_fetched_via_proxy); |
| 12574 | EXPECT_TRUE( |
| 12575 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
| 12576 | |
| 12577 | LoadTimingInfo load_timing_info; |
| 12578 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 12579 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12580 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 12581 | } |
| 12582 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12583 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 12584 | // while establishing the tunnel. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12585 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12586 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12587 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12588 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12589 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12590 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12591 | HttpRequestInfo request; |
| 12592 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12593 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12594 | |
| 12595 | // Since we have proxy, should try to establish tunnel. |
| 12596 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12597 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12598 | "Host: www.example.org:443\r\n" |
| 12599 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12600 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12601 | MockWrite("GET / HTTP/1.1\r\n" |
| 12602 | "Host: www.example.org\r\n" |
| 12603 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12604 | }; |
| 12605 | |
| 12606 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12607 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12608 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12609 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12610 | }; |
| 12611 | |
| 12612 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12613 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12614 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12615 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12616 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12617 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12618 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12619 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12620 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12621 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12622 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12623 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12624 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12625 | |
| 12626 | rv = callback1.WaitForResult(); |
| 12627 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 12628 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12629 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12630 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12631 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12632 | NetLog::PHASE_NONE); |
| 12633 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12634 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12635 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12636 | NetLog::PHASE_NONE); |
| 12637 | } |
| 12638 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12639 | // Test for crbug.com/55424. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12640 | TEST_P(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12641 | std::unique_ptr<SpdySerializedFrame> req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12642 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12643 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12644 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12645 | std::unique_ptr<SpdySerializedFrame> resp( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 12646 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12647 | std::unique_ptr<SpdySerializedFrame> data( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 12648 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12649 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12650 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12651 | }; |
| 12652 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12653 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12654 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12655 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12656 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12657 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12658 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12659 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12660 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12661 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12662 | |
| 12663 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12664 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12665 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 12666 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12667 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12668 | CreateInsecureSpdySession(session.get(), key, BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12669 | |
| 12670 | HttpRequestInfo request; |
| 12671 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12672 | request.url = GURL("https://www.example.org/"); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12673 | request.load_flags = 0; |
| 12674 | |
| 12675 | // This is the important line that marks this as a preconnect. |
| 12676 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 12677 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12678 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12679 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12680 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12681 | TestCompletionCallback callback; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12682 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12683 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12684 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12685 | } |
| 12686 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12687 | // Given a net error, cause that error to be returned from the first Write() |
| 12688 | // call and verify that the HttpTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12689 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12690 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12691 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12692 | request_info.url = GURL("https://www.example.com/"); |
| 12693 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12694 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12695 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12696 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12697 | MockWrite data_writes[] = { |
| 12698 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12699 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12700 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12701 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12702 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12703 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12704 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12705 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12706 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12707 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12708 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12709 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 12710 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12711 | rv = callback.WaitForResult(); |
| 12712 | ASSERT_EQ(error, rv); |
| 12713 | } |
| 12714 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12715 | TEST_P(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12716 | // Just check a grab bag of cert errors. |
| 12717 | static const int kErrors[] = { |
| 12718 | ERR_CERT_COMMON_NAME_INVALID, |
| 12719 | ERR_CERT_AUTHORITY_INVALID, |
| 12720 | ERR_CERT_DATE_INVALID, |
| 12721 | }; |
| 12722 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12723 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 12724 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12725 | } |
| 12726 | } |
| 12727 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12728 | // Ensure that a client certificate is removed from the SSL client auth |
| 12729 | // cache when: |
| 12730 | // 1) No proxy is involved. |
| 12731 | // 2) TLS False Start is disabled. |
| 12732 | // 3) The initial TLS handshake requests a client certificate. |
| 12733 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12734 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 12735 | ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12736 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12737 | request_info.url = GURL("https://www.example.com/"); |
| 12738 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12739 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12740 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12741 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12742 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12743 | |
| 12744 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 12745 | // CertificateRequest is received for the first time, the handshake will |
| 12746 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12747 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12748 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12749 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12750 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12751 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12752 | |
| 12753 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 12754 | // False Start is not being used, the result of the SSL handshake will be |
| 12755 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 12756 | // matches the result of a server sending a handshake_failure alert, |
| 12757 | // rather than a Finished message, because it requires a client |
| 12758 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12759 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12760 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12761 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12762 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12763 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12764 | |
| 12765 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 12766 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 12767 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 12768 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12769 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 12770 | // requiring a client certificate, this fallback handshake should also |
| 12771 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12772 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12773 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12774 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12775 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12776 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12777 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12778 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 12779 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 12780 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 12781 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12782 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 12783 | // requiring a client certificate, this fallback handshake should also |
| 12784 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12785 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12786 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12787 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12788 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12789 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12790 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12791 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12792 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12793 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12794 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12795 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12796 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12797 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 12798 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12799 | |
| 12800 | // Complete the SSL handshake, which should abort due to requiring a |
| 12801 | // client certificate. |
| 12802 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12803 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12804 | |
| 12805 | // Indicate that no certificate should be supplied. From the perspective |
| 12806 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 12807 | // certificate, so this is the same as supply a |
| 12808 | // legitimate-but-unacceptable certificate. |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12809 | rv = trans->RestartWithCertificate(NULL, NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12810 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12811 | |
| 12812 | // Ensure the certificate was added to the client auth cache before |
| 12813 | // allowing the connection to continue restarting. |
| 12814 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12815 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12816 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12817 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12818 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12819 | |
| 12820 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12821 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 12822 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12823 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12824 | ASSERT_EQ(ERR_SSL_PROTOCOL_ERROR, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12825 | |
| 12826 | // Ensure that the client certificate is removed from the cache on a |
| 12827 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12828 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12829 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12830 | } |
| 12831 | |
| 12832 | // Ensure that a client certificate is removed from the SSL client auth |
| 12833 | // cache when: |
| 12834 | // 1) No proxy is involved. |
| 12835 | // 2) TLS False Start is enabled. |
| 12836 | // 3) The initial TLS handshake requests a client certificate. |
| 12837 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12838 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 12839 | ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12840 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12841 | request_info.url = GURL("https://www.example.com/"); |
| 12842 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12843 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12844 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12845 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12846 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12847 | |
| 12848 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 12849 | // return successfully after reading up to the peer's Certificate message. |
| 12850 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 12851 | // enqueue application data to be sent in the same packet as the |
| 12852 | // ChangeCipherSpec and Finished messages. |
| 12853 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 12854 | // called, which expects to process the peer's ChangeCipherSpec and |
| 12855 | // Finished messages. If there was an error negotiating with the peer, |
| 12856 | // such as due to the peer requiring a client certificate when none was |
| 12857 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 12858 | // called. |
| 12859 | |
| 12860 | // Like the non-False Start case, when a client certificate is requested by |
| 12861 | // the peer, the handshake is aborted during the Connect() call. |
| 12862 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12863 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12864 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12865 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12866 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12867 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12868 | |
| 12869 | // When a client certificate is supplied, Connect() will not be aborted |
| 12870 | // when the peer requests the certificate. Instead, the handshake will |
| 12871 | // artificially succeed, allowing the caller to write the HTTP request to |
| 12872 | // the socket. The handshake messages are not processed until Read() is |
| 12873 | // called, which then detects that the handshake was aborted, due to the |
| 12874 | // peer sending a handshake_failure because it requires a client |
| 12875 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12876 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12877 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12878 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12879 | MockRead data2_reads[] = { |
| 12880 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12881 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12882 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12883 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12884 | |
| 12885 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12886 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 12887 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12888 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12889 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12890 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12891 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12892 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12893 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12894 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 12895 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12896 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12897 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12898 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12899 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12900 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12901 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 12902 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12903 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 12904 | ssl_data5.cert_request_info = cert_request.get(); |
| 12905 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12906 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 12907 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 12908 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12909 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12910 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12911 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12912 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12913 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12914 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12915 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 12916 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12917 | |
| 12918 | // Complete the SSL handshake, which should abort due to requiring a |
| 12919 | // client certificate. |
| 12920 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12921 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12922 | |
| 12923 | // Indicate that no certificate should be supplied. From the perspective |
| 12924 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 12925 | // certificate, so this is the same as supply a |
| 12926 | // legitimate-but-unacceptable certificate. |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12927 | rv = trans->RestartWithCertificate(NULL, NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12928 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12929 | |
| 12930 | // Ensure the certificate was added to the client auth cache before |
| 12931 | // allowing the connection to continue restarting. |
| 12932 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12933 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12934 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12935 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12936 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12937 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12938 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12939 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 12940 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12941 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12942 | ASSERT_EQ(ERR_SSL_PROTOCOL_ERROR, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12943 | |
| 12944 | // Ensure that the client certificate is removed from the cache on a |
| 12945 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12946 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12947 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12948 | } |
| 12949 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12950 | // Ensure that a client certificate is removed from the SSL client auth |
| 12951 | // cache when: |
| 12952 | // 1) An HTTPS proxy is involved. |
| 12953 | // 3) The HTTPS proxy requests a client certificate. |
| 12954 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 12955 | // proxy. |
| 12956 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 12957 | // then for connecting to an HTTP endpoint. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12958 | TEST_P(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12959 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12960 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12961 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12962 | |
| 12963 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12964 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12965 | |
| 12966 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 12967 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 12968 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 12969 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12970 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12971 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12972 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12973 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12974 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12975 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12976 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12977 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12978 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12979 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12980 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12981 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12982 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 12983 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12984 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12985 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12986 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12987 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12988 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12989 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12990 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12991 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12992 | requests[0].url = GURL("https://www.example.com/"); |
| 12993 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12994 | requests[0].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12995 | |
| 12996 | requests[1].url = GURL("http://www.example.com/"); |
| 12997 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12998 | requests[1].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12999 | |
| 13000 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13001 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13002 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13003 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13004 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13005 | |
| 13006 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13007 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13008 | int rv = trans->Start(&requests[i], callback.callback(), BoundNetLog()); |
| 13009 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13010 | |
| 13011 | // Complete the SSL handshake, which should abort due to requiring a |
| 13012 | // client certificate. |
| 13013 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13014 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13015 | |
| 13016 | // Indicate that no certificate should be supplied. From the perspective |
| 13017 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13018 | // certificate, so this is the same as supply a |
| 13019 | // legitimate-but-unacceptable certificate. |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13020 | rv = trans->RestartWithCertificate(NULL, NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13021 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13022 | |
| 13023 | // Ensure the certificate was added to the client auth cache before |
| 13024 | // allowing the connection to continue restarting. |
| 13025 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13026 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13027 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13028 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13029 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13030 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 13031 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13032 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13033 | HostPortPair("www.example.com", 443), &client_cert, |
| 13034 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13035 | |
| 13036 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 13037 | // then consume ssl_data3, which should also fail. The result code is |
| 13038 | // checked against what ssl_data3 should return. |
| 13039 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13040 | ASSERT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13041 | |
| 13042 | // Now that the new handshake has failed, ensure that the client |
| 13043 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13044 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13045 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13046 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13047 | HostPortPair("www.example.com", 443), &client_cert, |
| 13048 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13049 | } |
| 13050 | } |
| 13051 | |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 13052 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 13053 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13054 | |
| 13055 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13056 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13057 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 13058 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 13059 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13060 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13061 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13062 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13063 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13064 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13065 | std::unique_ptr<SpdySerializedFrame> host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13066 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13067 | spdy_util_.UpdateWithStreamDestruction(1); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13068 | std::unique_ptr<SpdySerializedFrame> host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13069 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13070 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13071 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13072 | }; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13073 | std::unique_ptr<SpdySerializedFrame> host1_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13074 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13075 | std::unique_ptr<SpdySerializedFrame> host1_resp_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13076 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13077 | std::unique_ptr<SpdySerializedFrame> host2_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13078 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13079 | std::unique_ptr<SpdySerializedFrame> host2_resp_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13080 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13081 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13082 | CreateMockRead(*host1_resp, 1), |
| 13083 | CreateMockRead(*host1_resp_body, 2), |
| 13084 | CreateMockRead(*host2_resp, 4), |
| 13085 | CreateMockRead(*host2_resp_body, 5), |
| 13086 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13087 | }; |
| 13088 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13089 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13090 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13091 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13092 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13093 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13094 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 13095 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13096 | HttpRequestInfo request1; |
| 13097 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13098 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13099 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13100 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13101 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13102 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13103 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13104 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13105 | |
| 13106 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13107 | ASSERT_TRUE(response); |
| 13108 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13109 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13110 | |
| 13111 | std::string response_data; |
| 13112 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 13113 | EXPECT_EQ("hello!", response_data); |
| 13114 | |
| 13115 | // Preload www.gmail.com into HostCache. |
| 13116 | HostPortPair host_port("www.gmail.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 13117 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13118 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 13119 | rv = session_deps_.host_resolver->Resolve(resolve_info, |
| 13120 | DEFAULT_PRIORITY, |
| 13121 | &ignored, |
| 13122 | callback.callback(), |
| 13123 | NULL, |
| 13124 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 13125 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13126 | rv = callback.WaitForResult(); |
| 13127 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13128 | |
| 13129 | HttpRequestInfo request2; |
| 13130 | request2.method = "GET"; |
| 13131 | request2.url = GURL("https://www.gmail.com/"); |
| 13132 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13133 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13134 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13135 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13136 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13137 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13138 | |
| 13139 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13140 | ASSERT_TRUE(response); |
| 13141 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13142 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13143 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13144 | EXPECT_TRUE(response->was_npn_negotiated); |
| 13145 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 13146 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13147 | } |
| 13148 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13149 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 13150 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13151 | |
| 13152 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13153 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13154 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13155 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 13156 | pool_peer.DisableDomainAuthenticationVerification(); |
| 13157 | |
| 13158 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13159 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13160 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13161 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13162 | std::unique_ptr<SpdySerializedFrame> host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13163 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13164 | spdy_util_.UpdateWithStreamDestruction(1); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13165 | std::unique_ptr<SpdySerializedFrame> host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13166 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13167 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13168 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13169 | }; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13170 | std::unique_ptr<SpdySerializedFrame> host1_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13171 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13172 | std::unique_ptr<SpdySerializedFrame> host1_resp_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13173 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13174 | std::unique_ptr<SpdySerializedFrame> host2_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13175 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13176 | std::unique_ptr<SpdySerializedFrame> host2_resp_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13177 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13178 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13179 | CreateMockRead(*host1_resp, 1), |
| 13180 | CreateMockRead(*host1_resp_body, 2), |
| 13181 | CreateMockRead(*host2_resp, 4), |
| 13182 | CreateMockRead(*host2_resp_body, 5), |
| 13183 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13184 | }; |
| 13185 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13186 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13187 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13188 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13189 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13190 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13191 | |
| 13192 | TestCompletionCallback callback; |
| 13193 | HttpRequestInfo request1; |
| 13194 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13195 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13196 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13197 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13198 | |
| 13199 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
| 13200 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13201 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 13202 | |
| 13203 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13204 | ASSERT_TRUE(response); |
| 13205 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13206 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13207 | |
| 13208 | std::string response_data; |
| 13209 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 13210 | EXPECT_EQ("hello!", response_data); |
| 13211 | |
| 13212 | HttpRequestInfo request2; |
| 13213 | request2.method = "GET"; |
| 13214 | request2.url = GURL("https://www.gmail.com/"); |
| 13215 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13216 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13217 | |
| 13218 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
| 13219 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13220 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 13221 | |
| 13222 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13223 | ASSERT_TRUE(response); |
| 13224 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13225 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13226 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13227 | EXPECT_TRUE(response->was_npn_negotiated); |
| 13228 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 13229 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13230 | } |
| 13231 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13232 | class OneTimeCachingHostResolver : public HostResolver { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13233 | public: |
| 13234 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
| 13235 | : host_port_(host_port) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13236 | ~OneTimeCachingHostResolver() override {} |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13237 | |
| 13238 | RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); } |
| 13239 | |
| 13240 | // HostResolver methods: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13241 | int Resolve(const RequestInfo& info, |
| 13242 | RequestPriority priority, |
| 13243 | AddressList* addresses, |
| 13244 | const CompletionCallback& callback, |
| 13245 | RequestHandle* out_req, |
| 13246 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 13247 | return host_resolver_.Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 13248 | info, priority, addresses, callback, out_req, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 13249 | } |
| 13250 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13251 | int ResolveFromCache(const RequestInfo& info, |
| 13252 | AddressList* addresses, |
| 13253 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 13254 | int rv = host_resolver_.ResolveFromCache(info, addresses, net_log); |
| 13255 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
[email protected] | 98e1cd01 | 2011-11-08 15:33:09 | [diff] [blame] | 13256 | host_resolver_.GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13257 | return rv; |
| 13258 | } |
| 13259 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13260 | void CancelRequest(RequestHandle req) override { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13261 | host_resolver_.CancelRequest(req); |
| 13262 | } |
| 13263 | |
[email protected] | 46da33be | 2011-07-19 21:58:04 | [diff] [blame] | 13264 | MockCachingHostResolver* GetMockHostResolver() { |
| 13265 | return &host_resolver_; |
| 13266 | } |
| 13267 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13268 | private: |
| 13269 | MockCachingHostResolver host_resolver_; |
| 13270 | const HostPortPair host_port_; |
| 13271 | }; |
| 13272 | |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 13273 | TEST_P(HttpNetworkTransactionTest, |
| 13274 | UseIPConnectionPoolingWithHostCacheExpiration) { |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 13275 | session_deps_.enable_alternative_service_with_different_host = false; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13276 | |
| 13277 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13278 | OneTimeCachingHostResolver host_resolver(HostPortPair("www.gmail.com", 443)); |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 13279 | HttpNetworkSession::Params params = |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13280 | SpdySessionDependencies::CreateSessionParams(&session_deps_); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13281 | params.host_resolver = &host_resolver; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13282 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 13283 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 13284 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13285 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13286 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13287 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13288 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13289 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13290 | std::unique_ptr<SpdySerializedFrame> host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13291 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13292 | spdy_util_.UpdateWithStreamDestruction(1); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13293 | std::unique_ptr<SpdySerializedFrame> host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13294 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13295 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13296 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13297 | }; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13298 | std::unique_ptr<SpdySerializedFrame> host1_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13299 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13300 | std::unique_ptr<SpdySerializedFrame> host1_resp_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13301 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13302 | std::unique_ptr<SpdySerializedFrame> host2_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13303 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13304 | std::unique_ptr<SpdySerializedFrame> host2_resp_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13305 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13306 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13307 | CreateMockRead(*host1_resp, 1), |
| 13308 | CreateMockRead(*host1_resp_body, 2), |
| 13309 | CreateMockRead(*host2_resp, 4), |
| 13310 | CreateMockRead(*host2_resp_body, 5), |
| 13311 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13312 | }; |
| 13313 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13314 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13315 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13316 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13317 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13318 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13319 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 13320 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13321 | HttpRequestInfo request1; |
| 13322 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13323 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13324 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13325 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13326 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13327 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13328 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13329 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13330 | |
| 13331 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13332 | ASSERT_TRUE(response); |
| 13333 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13334 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13335 | |
| 13336 | std::string response_data; |
| 13337 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 13338 | EXPECT_EQ("hello!", response_data); |
| 13339 | |
| 13340 | // Preload cache entries into HostCache. |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 13341 | HostResolver::RequestInfo resolve_info(HostPortPair("www.gmail.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13342 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 13343 | rv = host_resolver.Resolve(resolve_info, |
| 13344 | DEFAULT_PRIORITY, |
| 13345 | &ignored, |
| 13346 | callback.callback(), |
| 13347 | NULL, |
| 13348 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 13349 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13350 | rv = callback.WaitForResult(); |
| 13351 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13352 | |
| 13353 | HttpRequestInfo request2; |
| 13354 | request2.method = "GET"; |
| 13355 | request2.url = GURL("https://www.gmail.com/"); |
| 13356 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13357 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13358 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13359 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13360 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13361 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13362 | |
| 13363 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13364 | ASSERT_TRUE(response); |
| 13365 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13366 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13367 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13368 | EXPECT_TRUE(response->was_npn_negotiated); |
| 13369 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 13370 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13371 | } |
| 13372 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13373 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13374 | const std::string https_url = "https://www.example.org:8080/"; |
| 13375 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13376 | |
| 13377 | // SPDY GET for HTTPS URL |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13378 | std::unique_ptr<SpdySerializedFrame> req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13379 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13380 | |
| 13381 | MockWrite writes1[] = { |
| 13382 | CreateMockWrite(*req1, 0), |
| 13383 | }; |
| 13384 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13385 | std::unique_ptr<SpdySerializedFrame> resp1( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 13386 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13387 | std::unique_ptr<SpdySerializedFrame> body1( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 13388 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 13389 | MockRead reads1[] = {CreateMockRead(*resp1, 1), CreateMockRead(*body1, 2), |
| 13390 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13391 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13392 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 13393 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13394 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13395 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13396 | |
| 13397 | // HTTP GET for the HTTP URL |
| 13398 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13399 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13400 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13401 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13402 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13403 | }; |
| 13404 | |
| 13405 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13406 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 13407 | MockRead(ASYNC, 2, "hello"), |
| 13408 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13409 | }; |
| 13410 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13411 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 13412 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13413 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13414 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13415 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13416 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13417 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13418 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13419 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13420 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13421 | |
| 13422 | // Start the first transaction to set up the SpdySession |
| 13423 | HttpRequestInfo request1; |
| 13424 | request1.method = "GET"; |
| 13425 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13426 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13427 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13428 | TestCompletionCallback callback1; |
| 13429 | EXPECT_EQ(ERR_IO_PENDING, |
| 13430 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13431 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13432 | |
| 13433 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 13434 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 13435 | |
| 13436 | // Now, start the HTTP request |
| 13437 | HttpRequestInfo request2; |
| 13438 | request2.method = "GET"; |
| 13439 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13440 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13441 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13442 | TestCompletionCallback callback2; |
| 13443 | EXPECT_EQ(ERR_IO_PENDING, |
| 13444 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13445 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13446 | |
| 13447 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 13448 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 13449 | } |
| 13450 | |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13451 | class AltSvcCertificateVerificationTest : public HttpNetworkTransactionTest { |
| 13452 | public: |
| 13453 | void Run(bool pooling, bool valid) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13454 | url::SchemeHostPort server(GURL(valid ? "https://mail.example.org:443" |
| 13455 | : "https://invalid.example.org:443")); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13456 | HostPortPair alternative("www.example.org", 443); |
| 13457 | |
| 13458 | base::FilePath certs_dir = GetTestCertsDirectory(); |
| 13459 | scoped_refptr<X509Certificate> cert( |
| 13460 | ImportCertFromFile(certs_dir, "spdy_pooling.pem")); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13461 | ASSERT_TRUE(cert); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13462 | bool common_name_fallback_used; |
| 13463 | EXPECT_EQ(valid, |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13464 | cert->VerifyNameMatch(server.host(), &common_name_fallback_used)); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13465 | EXPECT_TRUE( |
| 13466 | cert->VerifyNameMatch(alternative.host(), &common_name_fallback_used)); |
| 13467 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13468 | ssl.SetNextProto(GetProtocol()); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13469 | ssl.cert = cert; |
| 13470 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13471 | |
| 13472 | // If pooling, then start a request to alternative first to create a |
| 13473 | // SpdySession. |
| 13474 | std::string url0 = "https://www.example.org:443"; |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13475 | // Second request to server, which has an alternative service, and could |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13476 | // open a connection to the alternative host or pool to the existing one. |
| 13477 | std::string url1("https://"); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13478 | url1.append(server.host()); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13479 | url1.append(":443"); |
| 13480 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13481 | std::unique_ptr<SpdySerializedFrame> req0; |
| 13482 | std::unique_ptr<SpdySerializedFrame> req1; |
| 13483 | std::unique_ptr<SpdySerializedFrame> resp0; |
| 13484 | std::unique_ptr<SpdySerializedFrame> body0; |
| 13485 | std::unique_ptr<SpdySerializedFrame> resp1; |
| 13486 | std::unique_ptr<SpdySerializedFrame> body1; |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13487 | std::vector<MockWrite> writes; |
| 13488 | std::vector<MockRead> reads; |
| 13489 | |
| 13490 | if (pooling) { |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13491 | req0.reset(spdy_util_.ConstructSpdyGet(url0.c_str(), 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13492 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13493 | req1.reset(spdy_util_.ConstructSpdyGet(url1.c_str(), 3, LOWEST)); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13494 | |
| 13495 | writes.push_back(CreateMockWrite(*req0, 0)); |
| 13496 | writes.push_back(CreateMockWrite(*req1, 3)); |
| 13497 | |
| 13498 | resp0.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13499 | body0.reset(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 13500 | resp1.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 13501 | body1.reset(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
| 13502 | |
| 13503 | reads.push_back(CreateMockRead(*resp0, 1)); |
| 13504 | reads.push_back(CreateMockRead(*body0, 2)); |
| 13505 | reads.push_back(MockRead(ASYNC, ERR_IO_PENDING, 4)); |
| 13506 | reads.push_back(CreateMockRead(*resp1, 5)); |
| 13507 | reads.push_back(CreateMockRead(*body1, 6)); |
| 13508 | reads.push_back(MockRead(ASYNC, OK, 7)); |
| 13509 | } else { |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13510 | req1.reset(spdy_util_.ConstructSpdyGet(url1.c_str(), 1, LOWEST)); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13511 | |
| 13512 | writes.push_back(CreateMockWrite(*req1, 0)); |
| 13513 | |
| 13514 | resp1.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13515 | body1.reset(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 13516 | |
| 13517 | reads.push_back(CreateMockRead(*resp1, 1)); |
| 13518 | reads.push_back(CreateMockRead(*body1, 2)); |
| 13519 | reads.push_back(MockRead(ASYNC, OK, 3)); |
| 13520 | } |
| 13521 | |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 13522 | SequencedSocketData data(reads.data(), reads.size(), writes.data(), |
| 13523 | writes.size()); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13524 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13525 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13526 | // Connection to the server fails. |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13527 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 13528 | StaticSocketDataProvider data_refused; |
| 13529 | data_refused.set_connect_data(mock_connect); |
| 13530 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13531 | |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 13532 | session_deps_.enable_alternative_service_with_different_host = true; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13533 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13534 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 13535 | session->http_server_properties(); |
| 13536 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13537 | AlternateProtocolFromNextProto(GetProtocol()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13538 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13539 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 13540 | expiration); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13541 | |
| 13542 | // First request to alternative. |
| 13543 | if (pooling) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13544 | std::unique_ptr<HttpTransaction> trans0( |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13545 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13546 | HttpRequestInfo request0; |
| 13547 | request0.method = "GET"; |
| 13548 | request0.url = GURL(url0); |
| 13549 | request0.load_flags = 0; |
| 13550 | TestCompletionCallback callback0; |
| 13551 | |
| 13552 | int rv = trans0->Start(&request0, callback0.callback(), BoundNetLog()); |
| 13553 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13554 | rv = callback0.WaitForResult(); |
| 13555 | EXPECT_EQ(OK, rv); |
| 13556 | } |
| 13557 | |
| 13558 | // Second request to origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13559 | std::unique_ptr<HttpTransaction> trans1( |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13560 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13561 | HttpRequestInfo request1; |
| 13562 | request1.method = "GET"; |
| 13563 | request1.url = GURL(url1); |
| 13564 | request1.load_flags = 0; |
| 13565 | TestCompletionCallback callback1; |
| 13566 | |
| 13567 | int rv = trans1->Start(&request1, callback1.callback(), BoundNetLog()); |
| 13568 | EXPECT_EQ(ERR_IO_PENDING, rv); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13569 | base::RunLoop().RunUntilIdle(); |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 13570 | if (data.IsPaused()) |
| 13571 | data.Resume(); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13572 | rv = callback1.WaitForResult(); |
| 13573 | if (valid) { |
| 13574 | EXPECT_EQ(OK, rv); |
| 13575 | } else { |
| 13576 | if (pooling) { |
| 13577 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 13578 | } else { |
| 13579 | EXPECT_EQ(ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN, rv); |
| 13580 | } |
| 13581 | } |
| 13582 | } |
| 13583 | }; |
| 13584 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13585 | INSTANTIATE_TEST_CASE_P(ProtoPlusDepend, |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13586 | AltSvcCertificateVerificationTest, |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13587 | testing::Values(kTestCaseSPDY31, |
| 13588 | kTestCaseHTTP2NoPriorityDependencies, |
| 13589 | kTestCaseHTTP2PriorityDependencies)); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13590 | |
| 13591 | // The alternative service host must exhibit a certificate that is valid for the |
| 13592 | // origin host. Test that this is enforced when pooling to an existing |
| 13593 | // connection. |
| 13594 | TEST_P(AltSvcCertificateVerificationTest, PoolingValid) { |
| 13595 | Run(true, true); |
| 13596 | } |
| 13597 | |
| 13598 | TEST_P(AltSvcCertificateVerificationTest, PoolingInvalid) { |
| 13599 | Run(true, false); |
| 13600 | } |
| 13601 | |
| 13602 | // The alternative service host must exhibit a certificate that is valid for the |
| 13603 | // origin host. Test that this is enforced when opening a new connection. |
| 13604 | TEST_P(AltSvcCertificateVerificationTest, NewConnectionValid) { |
| 13605 | Run(false, true); |
| 13606 | } |
| 13607 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13608 | // TODO(bnc): Re-enable when https://crbug.com/615413 is fixed. |
| 13609 | TEST_P(AltSvcCertificateVerificationTest, DISABLED_NewConnectionInvalid) { |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13610 | Run(false, false); |
| 13611 | } |
| 13612 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13613 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 13614 | // with the alternative server. That connection should not be used. |
| 13615 | TEST_P(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13616 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 13617 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13618 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13619 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13620 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13621 | ssl.SetNextProto(kProtoHTTP11); |
| 13622 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13623 | |
| 13624 | // No data should be read from the alternative, because HTTP/1.1 is |
| 13625 | // negotiated. |
| 13626 | StaticSocketDataProvider data; |
| 13627 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13628 | |
| 13629 | // This test documents that an alternate Job should not be used if HTTP/1.1 is |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13630 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13631 | // mocked. This way the request relies on the alternate Job. |
| 13632 | StaticSocketDataProvider data_refused; |
| 13633 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 13634 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13635 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13636 | // Set up alternative service for server. |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 13637 | session_deps_.enable_alternative_service_with_different_host = true; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13638 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13639 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 13640 | session->http_server_properties(); |
| 13641 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13642 | AlternateProtocolFromNextProto(GetProtocol()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13643 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13644 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 13645 | expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13646 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13647 | std::unique_ptr<HttpTransaction> trans( |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13648 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13649 | HttpRequestInfo request; |
| 13650 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13651 | request.url = GURL("https://www.example.org:443"); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13652 | request.load_flags = 0; |
| 13653 | TestCompletionCallback callback; |
| 13654 | |
| 13655 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
| 13656 | // negotiated, the alternate Job should fail with ERR_NPN_NEGOTIATION_FAILED. |
| 13657 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13658 | EXPECT_EQ(ERR_NPN_NEGOTIATION_FAILED, callback.GetResult(rv)); |
| 13659 | } |
| 13660 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13661 | // A request to a server with an alternative service fires two Jobs: one to the |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13662 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13663 | // succeeds, the request should succeed, even if the latter fails because |
| 13664 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
| 13665 | TEST_P(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13666 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 13667 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13668 | |
| 13669 | // Negotiate HTTP/1.1 with alternative. |
| 13670 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
| 13671 | alternative_ssl.SetNextProto(kProtoHTTP11); |
| 13672 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 13673 | |
| 13674 | // No data should be read from the alternative, because HTTP/1.1 is |
| 13675 | // negotiated. |
| 13676 | StaticSocketDataProvider data; |
| 13677 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13678 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13679 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13680 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
| 13681 | origin_ssl.SetNextProto(kProtoHTTP11); |
| 13682 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 13683 | |
| 13684 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13685 | MockWrite("GET / HTTP/1.1\r\n" |
| 13686 | "Host: www.example.org\r\n" |
| 13687 | "Connection: keep-alive\r\n\r\n"), |
| 13688 | MockWrite("GET /second HTTP/1.1\r\n" |
| 13689 | "Host: www.example.org\r\n" |
| 13690 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13691 | }; |
| 13692 | |
| 13693 | MockRead http_reads[] = { |
| 13694 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13695 | MockRead("Content-Type: text/html\r\n"), |
| 13696 | MockRead("Content-Length: 6\r\n\r\n"), |
| 13697 | MockRead("foobar"), |
| 13698 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13699 | MockRead("Content-Type: text/html\r\n"), |
| 13700 | MockRead("Content-Length: 7\r\n\r\n"), |
| 13701 | MockRead("another"), |
| 13702 | }; |
| 13703 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13704 | http_writes, arraysize(http_writes)); |
| 13705 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13706 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13707 | // Set up alternative service for server. |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 13708 | session_deps_.enable_alternative_service_with_different_host = true; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13709 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13710 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 13711 | session->http_server_properties(); |
| 13712 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13713 | AlternateProtocolFromNextProto(GetProtocol()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13714 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13715 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 13716 | expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13717 | |
| 13718 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 13719 | HttpRequestInfo request1; |
| 13720 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13721 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13722 | request1.load_flags = 0; |
| 13723 | TestCompletionCallback callback1; |
| 13724 | |
| 13725 | int rv = trans1.Start(&request1, callback1.callback(), BoundNetLog()); |
| 13726 | rv = callback1.GetResult(rv); |
| 13727 | EXPECT_EQ(OK, rv); |
| 13728 | |
| 13729 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13730 | ASSERT_TRUE(response1); |
| 13731 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13732 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 13733 | |
| 13734 | std::string response_data1; |
| 13735 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data1)); |
| 13736 | EXPECT_EQ("foobar", response_data1); |
| 13737 | |
| 13738 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 13739 | // for alternative service. |
| 13740 | EXPECT_TRUE( |
| 13741 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 13742 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13743 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13744 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13745 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13746 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 13747 | HttpRequestInfo request2; |
| 13748 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13749 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13750 | request2.load_flags = 0; |
| 13751 | TestCompletionCallback callback2; |
| 13752 | |
| 13753 | rv = trans2.Start(&request2, callback2.callback(), BoundNetLog()); |
| 13754 | rv = callback2.GetResult(rv); |
| 13755 | EXPECT_EQ(OK, rv); |
| 13756 | |
| 13757 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13758 | ASSERT_TRUE(response2); |
| 13759 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13760 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 13761 | |
| 13762 | std::string response_data2; |
| 13763 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data2)); |
| 13764 | EXPECT_EQ("another", response_data2); |
| 13765 | } |
| 13766 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13767 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 13768 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 13769 | // used. |
| 13770 | TEST_P(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13771 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13772 | HostPortPair alternative("alternative.example.org", 443); |
| 13773 | std::string origin_url = "https://origin.example.org:443"; |
| 13774 | std::string alternative_url = "https://alternative.example.org:443"; |
| 13775 | |
| 13776 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 13777 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13778 | ssl.SetNextProto(kProtoHTTP11); |
| 13779 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13780 | |
| 13781 | // HTTP/1.1 data for |request1| and |request2|. |
| 13782 | MockWrite http_writes[] = { |
| 13783 | MockWrite( |
| 13784 | "GET / HTTP/1.1\r\n" |
| 13785 | "Host: alternative.example.org\r\n" |
| 13786 | "Connection: keep-alive\r\n\r\n"), |
| 13787 | MockWrite( |
| 13788 | "GET / HTTP/1.1\r\n" |
| 13789 | "Host: alternative.example.org\r\n" |
| 13790 | "Connection: keep-alive\r\n\r\n"), |
| 13791 | }; |
| 13792 | |
| 13793 | MockRead http_reads[] = { |
| 13794 | MockRead( |
| 13795 | "HTTP/1.1 200 OK\r\n" |
| 13796 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13797 | "Content-Length: 40\r\n\r\n" |
| 13798 | "first HTTP/1.1 response from alternative"), |
| 13799 | MockRead( |
| 13800 | "HTTP/1.1 200 OK\r\n" |
| 13801 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13802 | "Content-Length: 41\r\n\r\n" |
| 13803 | "second HTTP/1.1 response from alternative"), |
| 13804 | }; |
| 13805 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13806 | http_writes, arraysize(http_writes)); |
| 13807 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13808 | |
| 13809 | // This test documents that an alternate Job should not pool to an already |
| 13810 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13811 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13812 | StaticSocketDataProvider data_refused; |
| 13813 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 13814 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13815 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13816 | // Set up alternative service for server. |
bnc | f33fb31b | 2016-01-29 15:22:26 | [diff] [blame] | 13817 | session_deps_.enable_alternative_service_with_different_host = false; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13818 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13819 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 13820 | session->http_server_properties(); |
| 13821 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13822 | AlternateProtocolFromNextProto(GetProtocol()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13823 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13824 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 13825 | expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13826 | |
| 13827 | // First transaction to alternative to open an HTTP/1.1 socket. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13828 | std::unique_ptr<HttpTransaction> trans1( |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13829 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13830 | HttpRequestInfo request1; |
| 13831 | request1.method = "GET"; |
| 13832 | request1.url = GURL(alternative_url); |
| 13833 | request1.load_flags = 0; |
| 13834 | TestCompletionCallback callback1; |
| 13835 | |
| 13836 | int rv = trans1->Start(&request1, callback1.callback(), BoundNetLog()); |
| 13837 | EXPECT_EQ(OK, callback1.GetResult(rv)); |
| 13838 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 13839 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13840 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13841 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 13842 | EXPECT_TRUE(response1->was_npn_negotiated); |
| 13843 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 13844 | std::string response_data1; |
| 13845 | ASSERT_EQ(OK, ReadTransaction(trans1.get(), &response_data1)); |
| 13846 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 13847 | |
| 13848 | // Request for origin.example.org, which has an alternative service. This |
| 13849 | // will start two Jobs: the alternative looks for connections to pool to, |
| 13850 | // finds one which is HTTP/1.1, and should ignore it, and should not try to |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13851 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13852 | // this request fails. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13853 | std::unique_ptr<HttpTransaction> trans2( |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13854 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13855 | HttpRequestInfo request2; |
| 13856 | request2.method = "GET"; |
| 13857 | request2.url = GURL(origin_url); |
| 13858 | request2.load_flags = 0; |
| 13859 | TestCompletionCallback callback2; |
| 13860 | |
| 13861 | rv = trans2->Start(&request2, callback2.callback(), BoundNetLog()); |
| 13862 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback2.GetResult(rv)); |
| 13863 | |
| 13864 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 13865 | // socket is still open and in the pool. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13866 | std::unique_ptr<HttpTransaction> trans3( |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13867 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13868 | HttpRequestInfo request3; |
| 13869 | request3.method = "GET"; |
| 13870 | request3.url = GURL(alternative_url); |
| 13871 | request3.load_flags = 0; |
| 13872 | TestCompletionCallback callback3; |
| 13873 | |
| 13874 | rv = trans3->Start(&request3, callback3.callback(), BoundNetLog()); |
| 13875 | EXPECT_EQ(OK, callback3.GetResult(rv)); |
| 13876 | const HttpResponseInfo* response3 = trans3->GetResponseInfo(); |
| 13877 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13878 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13879 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
| 13880 | EXPECT_TRUE(response3->was_npn_negotiated); |
| 13881 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 13882 | std::string response_data3; |
| 13883 | ASSERT_EQ(OK, ReadTransaction(trans3.get(), &response_data3)); |
| 13884 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 13885 | } |
| 13886 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13887 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13888 | const std::string https_url = "https://www.example.org:8080/"; |
| 13889 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13890 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13891 | // Separate SPDY util instance for naked and wrapped requests. |
| 13892 | SpdyTestUtil spdy_util_wrapped(GetProtocol(), GetDependenciesFromPriority()); |
| 13893 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13894 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13895 | const HostPortPair host_port_pair("www.example.org", 8080); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13896 | std::unique_ptr<SpdySerializedFrame> connect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13897 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13898 | std::unique_ptr<SpdySerializedFrame> req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13899 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13900 | std::unique_ptr<SpdySerializedFrame> wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13901 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 13902 | |
| 13903 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13904 | SpdyHeaderBlock req2_block; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 13905 | spdy_util_.MaybeAddVersionHeader(&req2_block); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13906 | req2_block[spdy_util_.GetMethodKey()] = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13907 | req2_block[spdy_util_.GetHostKey()] = "www.example.org:8080"; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13908 | req2_block[spdy_util_.GetSchemeKey()] = "http"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 13909 | req2_block[spdy_util_.GetPathKey()] = "/"; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13910 | std::unique_ptr<SpdySerializedFrame> req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13911 | spdy_util_.ConstructSpdySyn(3, req2_block, MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13912 | |
| 13913 | MockWrite writes1[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13914 | CreateMockWrite(*connect, 0), CreateMockWrite(*wrapped_req1, 2), |
| 13915 | CreateMockWrite(*req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13916 | }; |
| 13917 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13918 | std::unique_ptr<SpdySerializedFrame> conn_resp( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13919 | spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13920 | std::unique_ptr<SpdySerializedFrame> resp1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13921 | spdy_util_wrapped.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13922 | std::unique_ptr<SpdySerializedFrame> body1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13923 | spdy_util_wrapped.ConstructSpdyBodyFrame(1, true)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13924 | std::unique_ptr<SpdySerializedFrame> wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13925 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13926 | std::unique_ptr<SpdySerializedFrame> wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13927 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13928 | std::unique_ptr<SpdySerializedFrame> resp2( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 13929 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13930 | std::unique_ptr<SpdySerializedFrame> body2( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 13931 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13932 | MockRead reads1[] = { |
| 13933 | CreateMockRead(*conn_resp, 1), |
| 13934 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 13935 | CreateMockRead(*wrapped_resp1, 4), |
| 13936 | CreateMockRead(*wrapped_body1, 5), |
| 13937 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
| 13938 | CreateMockRead(*resp2, 8), |
| 13939 | CreateMockRead(*body2, 9), |
| 13940 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 13941 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13942 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13943 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 13944 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13945 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13946 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13947 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13948 | session_deps_.proxy_service = |
| 13949 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13950 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13951 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13952 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13953 | ssl1.SetNextProto(GetProtocol()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13954 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13955 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13956 | ssl2.SetNextProto(GetProtocol()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13957 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13958 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13959 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13960 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13961 | |
| 13962 | // Start the first transaction to set up the SpdySession |
| 13963 | HttpRequestInfo request1; |
| 13964 | request1.method = "GET"; |
| 13965 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13966 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13967 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13968 | TestCompletionCallback callback1; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13969 | int rv = trans1.Start(&request1, callback1.callback(), BoundNetLog()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13970 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13971 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 13972 | data1.RunUntilPaused(); |
| 13973 | base::RunLoop().RunUntilIdle(); |
| 13974 | data1.Resume(); |
| 13975 | EXPECT_EQ(OK, callback1.GetResult(rv)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13976 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 13977 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 13978 | LoadTimingInfo load_timing_info1; |
| 13979 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 13980 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 13981 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 13982 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13983 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13984 | HttpRequestInfo request2; |
| 13985 | request2.method = "GET"; |
| 13986 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13987 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13988 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13989 | TestCompletionCallback callback2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13990 | rv = trans2.Start(&request2, callback2.callback(), BoundNetLog()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13991 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13992 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 13993 | data1.RunUntilPaused(); |
| 13994 | base::RunLoop().RunUntilIdle(); |
| 13995 | data1.Resume(); |
| 13996 | EXPECT_EQ(OK, callback2.GetResult(rv)); |
| 13997 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13998 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 13999 | |
| 14000 | LoadTimingInfo load_timing_info2; |
| 14001 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 14002 | // The established SPDY sessions is considered reused by the HTTP request. |
| 14003 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 14004 | // HTTP requests over a SPDY session should have a different connection |
| 14005 | // socket_log_id than requests over a tunnel. |
| 14006 | 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] | 14007 | } |
| 14008 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14009 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 14010 | // that we do not pool other origins that resolve to the same IP when |
| 14011 | // the certificate does not match the new origin. |
| 14012 | // http://crbug.com/134690 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 14013 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14014 | const std::string url1 = "http://www.example.org/"; |
| 14015 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14016 | const std::string ip_addr = "1.2.3.4"; |
| 14017 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14018 | // Second SpdyTestUtil instance for the second socket. |
| 14019 | SpdyTestUtil spdy_util_secure(GetProtocol(), GetDependenciesFromPriority()); |
| 14020 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14021 | // SPDY GET for HTTP URL (through SPDY proxy) |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14022 | std::unique_ptr<SpdyHeaderBlock> headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14023 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14024 | std::unique_ptr<SpdySerializedFrame> req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14025 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14026 | |
| 14027 | MockWrite writes1[] = { |
| 14028 | CreateMockWrite(*req1, 0), |
| 14029 | }; |
| 14030 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14031 | std::unique_ptr<SpdySerializedFrame> resp1( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 14032 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14033 | std::unique_ptr<SpdySerializedFrame> body1( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 14034 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14035 | MockRead reads1[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14036 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(*resp1, 2), |
| 14037 | CreateMockRead(*body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14038 | }; |
| 14039 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14040 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 14041 | arraysize(writes1)); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 14042 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 14043 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14044 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14045 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14046 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14047 | |
| 14048 | // SPDY GET for HTTPS URL (direct) |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14049 | std::unique_ptr<SpdySerializedFrame> req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14050 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14051 | |
| 14052 | MockWrite writes2[] = { |
| 14053 | CreateMockWrite(*req2, 0), |
| 14054 | }; |
| 14055 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14056 | std::unique_ptr<SpdySerializedFrame> resp2( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14057 | spdy_util_secure.ConstructSpdyGetSynReply(NULL, 0, 1)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14058 | std::unique_ptr<SpdySerializedFrame> body2( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 14059 | spdy_util_secure.ConstructSpdyBodyFrame(1, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14060 | MockRead reads2[] = {CreateMockRead(*resp2, 1), CreateMockRead(*body2, 2), |
| 14061 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14062 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14063 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14064 | arraysize(writes2)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14065 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14066 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14067 | |
| 14068 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 14069 | // all others direct. |
| 14070 | ProxyConfig proxy_config; |
| 14071 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14072 | session_deps_.proxy_service.reset(new ProxyService( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14073 | base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), nullptr, |
csharrison | b7e3a08 | 2015-09-22 19:13:04 | [diff] [blame] | 14074 | NULL)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14075 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14076 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14077 | ssl1.SetNextProto(GetProtocol()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14078 | // Load a valid cert. Note, that this does not need to |
| 14079 | // be valid for proxy because the MockSSLClientSocket does |
| 14080 | // not actually verify it. But SpdySession will use this |
| 14081 | // to see if it is valid for the new origin |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14082 | ssl1.cert = ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14083 | ASSERT_TRUE(ssl1.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14084 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14085 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14086 | |
| 14087 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14088 | ssl2.SetNextProto(GetProtocol()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14089 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14090 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14091 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14092 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14093 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14094 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14095 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14096 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14097 | |
| 14098 | // Start the first transaction to set up the SpdySession |
| 14099 | HttpRequestInfo request1; |
| 14100 | request1.method = "GET"; |
| 14101 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14102 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14103 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14104 | TestCompletionCallback callback1; |
| 14105 | ASSERT_EQ(ERR_IO_PENDING, |
| 14106 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14107 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14108 | data1.RunUntilPaused(); |
| 14109 | base::RunLoop().RunUntilIdle(); |
| 14110 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14111 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14112 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 14113 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14114 | |
| 14115 | // Now, start the HTTP request |
| 14116 | HttpRequestInfo request2; |
| 14117 | request2.method = "GET"; |
| 14118 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14119 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14120 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14121 | TestCompletionCallback callback2; |
| 14122 | EXPECT_EQ(ERR_IO_PENDING, |
| 14123 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14124 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14125 | |
| 14126 | ASSERT_TRUE(callback2.have_result()); |
| 14127 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 14128 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14129 | } |
| 14130 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14131 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 14132 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 14133 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 14134 | // SpdySession) do work. http://crbug.com/224701 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 14135 | TEST_P(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14136 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14137 | |
| 14138 | MockRead reads1[] = { |
| 14139 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 14140 | }; |
| 14141 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14142 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14143 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14144 | std::unique_ptr<SpdySerializedFrame> req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14145 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14146 | MockWrite writes2[] = { |
| 14147 | CreateMockWrite(*req2, 0), |
| 14148 | }; |
| 14149 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14150 | std::unique_ptr<SpdySerializedFrame> resp2( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 14151 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14152 | std::unique_ptr<SpdySerializedFrame> body2( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 14153 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14154 | MockRead reads2[] = { |
| 14155 | CreateMockRead(*resp2, 1), |
| 14156 | CreateMockRead(*body2, 2), |
| 14157 | MockRead(ASYNC, OK, 3) // EOF |
| 14158 | }; |
| 14159 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14160 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14161 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14162 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14163 | SSLSocketDataProvider ssl1(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14164 | ssl1.SetNextProto(GetProtocol()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14165 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14166 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14167 | |
| 14168 | SSLSocketDataProvider ssl2(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14169 | ssl2.SetNextProto(GetProtocol()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14170 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14171 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14172 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14173 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14174 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14175 | |
| 14176 | // Start the first transaction to set up the SpdySession and verify that |
| 14177 | // connection was closed. |
| 14178 | HttpRequestInfo request1; |
| 14179 | request1.method = "GET"; |
| 14180 | request1.url = GURL(https_url); |
| 14181 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14182 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14183 | TestCompletionCallback callback1; |
| 14184 | EXPECT_EQ(ERR_IO_PENDING, |
| 14185 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14186 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback1.WaitForResult()); |
| 14187 | |
| 14188 | // Now, start the second request and make sure it succeeds. |
| 14189 | HttpRequestInfo request2; |
| 14190 | request2.method = "GET"; |
| 14191 | request2.url = GURL(https_url); |
| 14192 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14193 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14194 | TestCompletionCallback callback2; |
| 14195 | EXPECT_EQ(ERR_IO_PENDING, |
| 14196 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14197 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14198 | ASSERT_EQ(OK, callback2.WaitForResult()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14199 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14200 | } |
| 14201 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 14202 | TEST_P(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14203 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 14204 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14205 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 14206 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14207 | |
| 14208 | // Use two different hosts with different IPs so they don't get pooled. |
| 14209 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 14210 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14211 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14212 | |
| 14213 | SSLSocketDataProvider ssl1(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14214 | ssl1.SetNextProto(GetProtocol()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14215 | SSLSocketDataProvider ssl2(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14216 | ssl2.SetNextProto(GetProtocol()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14217 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14218 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14219 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14220 | std::unique_ptr<SpdySerializedFrame> host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14221 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14222 | MockWrite spdy1_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14223 | CreateMockWrite(*host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14224 | }; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14225 | std::unique_ptr<SpdySerializedFrame> host1_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 14226 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14227 | std::unique_ptr<SpdySerializedFrame> host1_resp_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 14228 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14229 | MockRead spdy1_reads[] = { |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14230 | CreateMockRead(*host1_resp, 1), CreateMockRead(*host1_resp_body, 2), |
| 14231 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14232 | }; |
| 14233 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14234 | // Use a separate test instance for the separate SpdySession that will be |
| 14235 | // created. |
| 14236 | SpdyTestUtil spdy_util_2(GetProtocol(), GetDependenciesFromPriority()); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14237 | std::unique_ptr<SequencedSocketData> spdy1_data( |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14238 | new SequencedSocketData(spdy1_reads, arraysize(spdy1_reads), spdy1_writes, |
| 14239 | arraysize(spdy1_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14240 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 14241 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14242 | std::unique_ptr<SpdySerializedFrame> host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14243 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14244 | MockWrite spdy2_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14245 | CreateMockWrite(*host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14246 | }; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14247 | std::unique_ptr<SpdySerializedFrame> host2_resp( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14248 | spdy_util_2.ConstructSpdyGetSynReply(NULL, 0, 1)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14249 | std::unique_ptr<SpdySerializedFrame> host2_resp_body( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14250 | spdy_util_2.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14251 | MockRead spdy2_reads[] = { |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14252 | CreateMockRead(*host2_resp, 1), CreateMockRead(*host2_resp_body, 2), |
| 14253 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14254 | }; |
| 14255 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14256 | std::unique_ptr<SequencedSocketData> spdy2_data( |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14257 | new SequencedSocketData(spdy2_reads, arraysize(spdy2_reads), spdy2_writes, |
| 14258 | arraysize(spdy2_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14259 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 14260 | |
| 14261 | MockWrite http_write[] = { |
| 14262 | MockWrite("GET / HTTP/1.1\r\n" |
| 14263 | "Host: www.a.com\r\n" |
| 14264 | "Connection: keep-alive\r\n\r\n"), |
| 14265 | }; |
| 14266 | |
| 14267 | MockRead http_read[] = { |
| 14268 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14269 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14270 | MockRead("Content-Length: 6\r\n\r\n"), |
| 14271 | MockRead("hello!"), |
| 14272 | }; |
| 14273 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 14274 | http_write, arraysize(http_write)); |
| 14275 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14276 | |
| 14277 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14278 | SpdySessionKey spdy_session_key_a( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14279 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14280 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14281 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14282 | |
| 14283 | TestCompletionCallback callback; |
| 14284 | HttpRequestInfo request1; |
| 14285 | request1.method = "GET"; |
| 14286 | request1.url = GURL("https://www.a.com/"); |
| 14287 | request1.load_flags = 0; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14288 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14289 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14290 | |
| 14291 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 14292 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14293 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 14294 | |
| 14295 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14296 | ASSERT_TRUE(response); |
| 14297 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14298 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14299 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14300 | EXPECT_TRUE(response->was_npn_negotiated); |
| 14301 | |
| 14302 | std::string response_data; |
| 14303 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 14304 | EXPECT_EQ("hello!", response_data); |
| 14305 | trans.reset(); |
| 14306 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14307 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14308 | |
| 14309 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14310 | SpdySessionKey spdy_session_key_b( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14311 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14312 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14313 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14314 | HttpRequestInfo request2; |
| 14315 | request2.method = "GET"; |
| 14316 | request2.url = GURL("https://www.b.com/"); |
| 14317 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14318 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14319 | |
| 14320 | rv = trans->Start(&request2, callback.callback(), BoundNetLog()); |
| 14321 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14322 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 14323 | |
| 14324 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14325 | ASSERT_TRUE(response); |
| 14326 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14327 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14328 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14329 | EXPECT_TRUE(response->was_npn_negotiated); |
| 14330 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 14331 | EXPECT_EQ("hello!", response_data); |
| 14332 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14333 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14334 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14335 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14336 | |
| 14337 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14338 | SpdySessionKey spdy_session_key_a1( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14339 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14340 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14341 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14342 | HttpRequestInfo request3; |
| 14343 | request3.method = "GET"; |
| 14344 | request3.url = GURL("http://www.a.com/"); |
| 14345 | request3.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14346 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14347 | |
| 14348 | rv = trans->Start(&request3, callback.callback(), BoundNetLog()); |
| 14349 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14350 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 14351 | |
| 14352 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14353 | ASSERT_TRUE(response); |
| 14354 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14355 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14356 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 14357 | EXPECT_FALSE(response->was_npn_negotiated); |
| 14358 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 14359 | EXPECT_EQ("hello!", response_data); |
| 14360 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14361 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14362 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14363 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14364 | } |
| 14365 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14366 | TEST_P(HttpNetworkTransactionTest, HttpSyncConnectError) { |
| 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 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14372 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14373 | std::unique_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 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14376 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14377 | StaticSocketDataProvider data; |
| 14378 | data.set_connect_data(mock_connect); |
| 14379 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14380 | |
| 14381 | TestCompletionCallback callback; |
| 14382 | |
| 14383 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14384 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14385 | |
| 14386 | rv = callback.WaitForResult(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14387 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14388 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14389 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 14390 | HttpRequestHeaders request_headers; |
| 14391 | trans->GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14392 | |
| 14393 | ConnectionAttempts attempts; |
| 14394 | trans->GetConnectionAttempts(&attempts); |
| 14395 | ASSERT_EQ(1u, attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14396 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, attempts[0].result); |
| 14397 | |
| 14398 | IPEndPoint endpoint; |
| 14399 | EXPECT_FALSE(trans->GetRemoteEndpoint(&endpoint)); |
| 14400 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14401 | } |
| 14402 | |
| 14403 | TEST_P(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
| 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 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14409 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14410 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14411 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14412 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14413 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14414 | StaticSocketDataProvider data; |
| 14415 | data.set_connect_data(mock_connect); |
| 14416 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14417 | |
| 14418 | TestCompletionCallback callback; |
| 14419 | |
| 14420 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14421 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14422 | |
| 14423 | rv = callback.WaitForResult(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14424 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14425 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14426 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 14427 | HttpRequestHeaders request_headers; |
| 14428 | trans->GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14429 | |
| 14430 | ConnectionAttempts attempts; |
| 14431 | trans->GetConnectionAttempts(&attempts); |
| 14432 | ASSERT_EQ(1u, attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14433 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, attempts[0].result); |
| 14434 | |
| 14435 | IPEndPoint endpoint; |
| 14436 | EXPECT_FALSE(trans->GetRemoteEndpoint(&endpoint)); |
| 14437 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14438 | } |
| 14439 | |
| 14440 | TEST_P(HttpNetworkTransactionTest, HttpSyncWriteError) { |
| 14441 | HttpRequestInfo request; |
| 14442 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14443 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14444 | request.load_flags = 0; |
| 14445 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14446 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14447 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14448 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14449 | |
| 14450 | MockWrite data_writes[] = { |
| 14451 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14452 | }; |
| 14453 | MockRead data_reads[] = { |
| 14454 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 14455 | }; |
| 14456 | |
| 14457 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14458 | data_writes, arraysize(data_writes)); |
| 14459 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14460 | |
| 14461 | TestCompletionCallback callback; |
| 14462 | |
| 14463 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14464 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14465 | |
| 14466 | rv = callback.WaitForResult(); |
| 14467 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 14468 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14469 | HttpRequestHeaders request_headers; |
| 14470 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 14471 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14472 | } |
| 14473 | |
| 14474 | TEST_P(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
| 14475 | HttpRequestInfo request; |
| 14476 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14477 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14478 | request.load_flags = 0; |
| 14479 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14480 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14481 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14482 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14483 | |
| 14484 | MockWrite data_writes[] = { |
| 14485 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 14486 | }; |
| 14487 | MockRead data_reads[] = { |
| 14488 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 14489 | }; |
| 14490 | |
| 14491 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14492 | data_writes, arraysize(data_writes)); |
| 14493 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14494 | |
| 14495 | TestCompletionCallback callback; |
| 14496 | |
| 14497 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14498 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14499 | |
| 14500 | rv = callback.WaitForResult(); |
| 14501 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 14502 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14503 | HttpRequestHeaders request_headers; |
| 14504 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 14505 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14506 | } |
| 14507 | |
| 14508 | TEST_P(HttpNetworkTransactionTest, HttpSyncReadError) { |
| 14509 | HttpRequestInfo request; |
| 14510 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14511 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14512 | request.load_flags = 0; |
| 14513 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14514 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14515 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14516 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14517 | |
| 14518 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14519 | MockWrite( |
| 14520 | "GET / HTTP/1.1\r\n" |
| 14521 | "Host: www.example.org\r\n" |
| 14522 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14523 | }; |
| 14524 | MockRead data_reads[] = { |
| 14525 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14526 | }; |
| 14527 | |
| 14528 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14529 | data_writes, arraysize(data_writes)); |
| 14530 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14531 | |
| 14532 | TestCompletionCallback callback; |
| 14533 | |
| 14534 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14535 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14536 | |
| 14537 | rv = callback.WaitForResult(); |
| 14538 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 14539 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14540 | HttpRequestHeaders request_headers; |
| 14541 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 14542 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14543 | } |
| 14544 | |
| 14545 | TEST_P(HttpNetworkTransactionTest, HttpAsyncReadError) { |
| 14546 | HttpRequestInfo request; |
| 14547 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14548 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14549 | request.load_flags = 0; |
| 14550 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14551 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14552 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14553 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14554 | |
| 14555 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14556 | MockWrite( |
| 14557 | "GET / HTTP/1.1\r\n" |
| 14558 | "Host: www.example.org\r\n" |
| 14559 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14560 | }; |
| 14561 | MockRead data_reads[] = { |
| 14562 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 14563 | }; |
| 14564 | |
| 14565 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14566 | data_writes, arraysize(data_writes)); |
| 14567 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14568 | |
| 14569 | TestCompletionCallback callback; |
| 14570 | |
| 14571 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14572 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14573 | |
| 14574 | rv = callback.WaitForResult(); |
| 14575 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 14576 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14577 | HttpRequestHeaders request_headers; |
| 14578 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 14579 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14580 | } |
| 14581 | |
| 14582 | TEST_P(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
| 14583 | HttpRequestInfo request; |
| 14584 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14585 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14586 | request.load_flags = 0; |
| 14587 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 14588 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14589 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14590 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14591 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14592 | |
| 14593 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14594 | MockWrite( |
| 14595 | "GET / HTTP/1.1\r\n" |
| 14596 | "Host: www.example.org\r\n" |
| 14597 | "Connection: keep-alive\r\n" |
| 14598 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14599 | }; |
| 14600 | MockRead data_reads[] = { |
| 14601 | MockRead("HTTP/1.1 200 OK\r\n" |
| 14602 | "Content-Length: 5\r\n\r\n" |
| 14603 | "hello"), |
| 14604 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 14605 | }; |
| 14606 | |
| 14607 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14608 | data_writes, arraysize(data_writes)); |
| 14609 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14610 | |
| 14611 | TestCompletionCallback callback; |
| 14612 | |
| 14613 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14614 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14615 | |
| 14616 | rv = callback.WaitForResult(); |
| 14617 | EXPECT_EQ(OK, rv); |
| 14618 | |
| 14619 | HttpRequestHeaders request_headers; |
| 14620 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 14621 | std::string foo; |
| 14622 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 14623 | EXPECT_EQ("bar", foo); |
| 14624 | } |
| 14625 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14626 | namespace { |
| 14627 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 14628 | // Fake HttpStream that simply records calls to SetPriority(). |
| 14629 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14630 | public base::SupportsWeakPtr<FakeStream> { |
| 14631 | public: |
| 14632 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14633 | ~FakeStream() override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14634 | |
| 14635 | RequestPriority priority() const { return priority_; } |
| 14636 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14637 | int InitializeStream(const HttpRequestInfo* request_info, |
| 14638 | RequestPriority priority, |
| 14639 | const BoundNetLog& net_log, |
| 14640 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14641 | return ERR_IO_PENDING; |
| 14642 | } |
| 14643 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14644 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 14645 | HttpResponseInfo* response, |
| 14646 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14647 | ADD_FAILURE(); |
| 14648 | return ERR_UNEXPECTED; |
| 14649 | } |
| 14650 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14651 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14652 | ADD_FAILURE(); |
| 14653 | return ERR_UNEXPECTED; |
| 14654 | } |
| 14655 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14656 | int ReadResponseBody(IOBuffer* buf, |
| 14657 | int buf_len, |
| 14658 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14659 | ADD_FAILURE(); |
| 14660 | return ERR_UNEXPECTED; |
| 14661 | } |
| 14662 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14663 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14664 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14665 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14666 | ADD_FAILURE(); |
| 14667 | return false; |
| 14668 | } |
| 14669 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14670 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14671 | ADD_FAILURE(); |
| 14672 | return false; |
| 14673 | } |
| 14674 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14675 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14676 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 14677 | bool CanReuseConnection() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14678 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 14679 | int64_t GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 14680 | ADD_FAILURE(); |
| 14681 | return 0; |
| 14682 | } |
| 14683 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 14684 | int64_t GetTotalSentBytes() const override { |
| 14685 | ADD_FAILURE(); |
| 14686 | return 0; |
| 14687 | } |
| 14688 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14689 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14690 | ADD_FAILURE(); |
| 14691 | return false; |
| 14692 | } |
| 14693 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14694 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 14695 | |
| 14696 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14697 | ADD_FAILURE(); |
| 14698 | } |
| 14699 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14700 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 14701 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 14702 | Error GetSignedEKMForTokenBinding(crypto::ECPrivateKey* key, |
| 14703 | std::vector<uint8_t>* out) override { |
| 14704 | ADD_FAILURE(); |
| 14705 | return ERR_NOT_IMPLEMENTED; |
| 14706 | } |
| 14707 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14708 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14709 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 14710 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 14711 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14712 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14713 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 14714 | UploadProgress GetUploadProgress() const override { return UploadProgress(); } |
| 14715 | |
| 14716 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 14717 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14718 | private: |
| 14719 | RequestPriority priority_; |
| 14720 | |
| 14721 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 14722 | }; |
| 14723 | |
| 14724 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 14725 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14726 | class FakeStreamRequest : public HttpStreamRequest, |
| 14727 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 14728 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14729 | FakeStreamRequest(RequestPriority priority, |
| 14730 | HttpStreamRequest::Delegate* delegate) |
| 14731 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14732 | delegate_(delegate), |
| 14733 | websocket_stream_create_helper_(NULL) {} |
| 14734 | |
| 14735 | FakeStreamRequest(RequestPriority priority, |
| 14736 | HttpStreamRequest::Delegate* delegate, |
| 14737 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 14738 | : priority_(priority), |
| 14739 | delegate_(delegate), |
| 14740 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14741 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14742 | ~FakeStreamRequest() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14743 | |
| 14744 | RequestPriority priority() const { return priority_; } |
| 14745 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14746 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 14747 | websocket_stream_create_helper() const { |
| 14748 | return websocket_stream_create_helper_; |
| 14749 | } |
| 14750 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14751 | // Create a new FakeStream and pass it to the request's |
| 14752 | // delegate. Returns a weak pointer to the FakeStream. |
| 14753 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
| 14754 | FakeStream* fake_stream = new FakeStream(priority_); |
| 14755 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 14756 | // immediately delete |fake_stream|. |
| 14757 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
| 14758 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), fake_stream); |
| 14759 | return weak_stream; |
| 14760 | } |
| 14761 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14762 | int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14763 | ADD_FAILURE(); |
| 14764 | return ERR_UNEXPECTED; |
| 14765 | } |
| 14766 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14767 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14768 | ADD_FAILURE(); |
| 14769 | return LoadState(); |
| 14770 | } |
| 14771 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14772 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14773 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14774 | bool was_npn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14775 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14776 | NextProto protocol_negotiated() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14777 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14778 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14779 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14780 | const ConnectionAttempts& connection_attempts() const override { |
| 14781 | static ConnectionAttempts no_attempts; |
| 14782 | return no_attempts; |
| 14783 | } |
| 14784 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14785 | private: |
| 14786 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14787 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14788 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14789 | |
| 14790 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 14791 | }; |
| 14792 | |
| 14793 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 14794 | class FakeStreamFactory : public HttpStreamFactory { |
| 14795 | public: |
| 14796 | FakeStreamFactory() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14797 | ~FakeStreamFactory() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14798 | |
| 14799 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 14800 | // RequestStream() (which may be NULL if it was destroyed already). |
| 14801 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 14802 | return last_stream_request_; |
| 14803 | } |
| 14804 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14805 | HttpStreamRequest* RequestStream(const HttpRequestInfo& info, |
| 14806 | RequestPriority priority, |
| 14807 | const SSLConfig& server_ssl_config, |
| 14808 | const SSLConfig& proxy_ssl_config, |
| 14809 | HttpStreamRequest::Delegate* delegate, |
| 14810 | const BoundNetLog& net_log) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14811 | FakeStreamRequest* fake_request = new FakeStreamRequest(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14812 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 14813 | return fake_request; |
| 14814 | } |
| 14815 | |
xunjieli | 5749218c | 2016-03-22 16:43:06 | [diff] [blame] | 14816 | HttpStreamRequest* RequestBidirectionalStreamImpl( |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 14817 | const HttpRequestInfo& info, |
| 14818 | RequestPriority priority, |
| 14819 | const SSLConfig& server_ssl_config, |
| 14820 | const SSLConfig& proxy_ssl_config, |
| 14821 | HttpStreamRequest::Delegate* delegate, |
| 14822 | const BoundNetLog& net_log) override { |
| 14823 | NOTREACHED(); |
| 14824 | return nullptr; |
| 14825 | } |
| 14826 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14827 | HttpStreamRequest* RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14828 | const HttpRequestInfo& info, |
| 14829 | RequestPriority priority, |
| 14830 | const SSLConfig& server_ssl_config, |
| 14831 | const SSLConfig& proxy_ssl_config, |
| 14832 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 14833 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 14834 | const BoundNetLog& net_log) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14835 | FakeStreamRequest* fake_request = |
| 14836 | new FakeStreamRequest(priority, delegate, create_helper); |
| 14837 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 14838 | return fake_request; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14839 | } |
| 14840 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14841 | void PreconnectStreams(int num_streams, |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 14842 | const HttpRequestInfo& info) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14843 | ADD_FAILURE(); |
| 14844 | } |
| 14845 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14846 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14847 | ADD_FAILURE(); |
| 14848 | return NULL; |
| 14849 | } |
| 14850 | |
| 14851 | private: |
| 14852 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 14853 | |
| 14854 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 14855 | }; |
| 14856 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14857 | // TODO(ricea): Maybe unify this with the one in |
| 14858 | // url_request_http_job_unittest.cc ? |
| 14859 | class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { |
| 14860 | public: |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14861 | FakeWebSocketBasicHandshakeStream( |
| 14862 | std::unique_ptr<ClientSocketHandle> connection, |
| 14863 | bool using_proxy) |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14864 | : state_(connection.release(), using_proxy) {} |
| 14865 | |
| 14866 | // Fake implementation of HttpStreamBase methods. |
| 14867 | // This ends up being quite "real" because this object has to really send data |
| 14868 | // on the mock socket. It might be easier to use the real implementation, but |
| 14869 | // the fact that the WebSocket code is not compiled on iOS makes that |
| 14870 | // difficult. |
| 14871 | int InitializeStream(const HttpRequestInfo* request_info, |
| 14872 | RequestPriority priority, |
| 14873 | const BoundNetLog& net_log, |
| 14874 | const CompletionCallback& callback) override { |
| 14875 | state_.Initialize(request_info, priority, net_log, callback); |
| 14876 | return OK; |
| 14877 | } |
| 14878 | |
| 14879 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 14880 | HttpResponseInfo* response, |
| 14881 | const CompletionCallback& callback) override { |
| 14882 | return parser()->SendRequest(state_.GenerateRequestLine(), request_headers, |
| 14883 | response, callback); |
| 14884 | } |
| 14885 | |
| 14886 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
| 14887 | return parser()->ReadResponseHeaders(callback); |
| 14888 | } |
| 14889 | |
| 14890 | int ReadResponseBody(IOBuffer* buf, |
| 14891 | int buf_len, |
| 14892 | const CompletionCallback& callback) override { |
| 14893 | NOTREACHED(); |
| 14894 | return ERR_IO_PENDING; |
| 14895 | } |
| 14896 | |
| 14897 | void Close(bool not_reusable) override { |
| 14898 | if (parser()) |
| 14899 | parser()->Close(true); |
| 14900 | } |
| 14901 | |
| 14902 | bool IsResponseBodyComplete() const override { |
| 14903 | NOTREACHED(); |
| 14904 | return false; |
| 14905 | } |
| 14906 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14907 | bool IsConnectionReused() const override { |
| 14908 | NOTREACHED(); |
| 14909 | return false; |
| 14910 | } |
| 14911 | void SetConnectionReused() override { NOTREACHED(); } |
| 14912 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 14913 | bool CanReuseConnection() const override { return false; } |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14914 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 14915 | int64_t GetTotalReceivedBytes() const override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14916 | NOTREACHED(); |
| 14917 | return 0; |
| 14918 | } |
| 14919 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 14920 | int64_t GetTotalSentBytes() const override { |
| 14921 | NOTREACHED(); |
| 14922 | return 0; |
| 14923 | } |
| 14924 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14925 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
| 14926 | NOTREACHED(); |
| 14927 | return false; |
| 14928 | } |
| 14929 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 14930 | void GetSSLInfo(SSLInfo* ssl_info) override {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14931 | |
| 14932 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
| 14933 | NOTREACHED(); |
| 14934 | } |
| 14935 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14936 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 14937 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 14938 | Error GetSignedEKMForTokenBinding(crypto::ECPrivateKey* key, |
| 14939 | std::vector<uint8_t>* out) override { |
| 14940 | ADD_FAILURE(); |
| 14941 | return ERR_NOT_IMPLEMENTED; |
| 14942 | } |
| 14943 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14944 | void Drain(HttpNetworkSession* session) override { NOTREACHED(); } |
| 14945 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 14946 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 14947 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14948 | void SetPriority(RequestPriority priority) override { NOTREACHED(); } |
| 14949 | |
| 14950 | UploadProgress GetUploadProgress() const override { |
| 14951 | NOTREACHED(); |
| 14952 | return UploadProgress(); |
| 14953 | } |
| 14954 | |
| 14955 | HttpStream* RenewStreamForAuth() override { |
| 14956 | NOTREACHED(); |
| 14957 | return nullptr; |
| 14958 | } |
| 14959 | |
| 14960 | // Fake implementation of WebSocketHandshakeStreamBase method(s) |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14961 | std::unique_ptr<WebSocketStream> Upgrade() override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14962 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14963 | return std::unique_ptr<WebSocketStream>(); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14964 | } |
| 14965 | |
| 14966 | private: |
| 14967 | HttpStreamParser* parser() const { return state_.parser(); } |
| 14968 | HttpBasicState state_; |
| 14969 | |
| 14970 | DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream); |
| 14971 | }; |
| 14972 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14973 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 14974 | // worth doing. |
| 14975 | class FakeWebSocketStreamCreateHelper : |
| 14976 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 14977 | public: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14978 | WebSocketHandshakeStreamBase* CreateBasicStream( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14979 | std::unique_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 14980 | bool using_proxy) override { |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 14981 | return new FakeWebSocketBasicHandshakeStream(std::move(connection), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14982 | using_proxy); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14983 | } |
| 14984 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14985 | WebSocketHandshakeStreamBase* CreateSpdyStream( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14986 | const base::WeakPtr<SpdySession>& session, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 14987 | bool use_relative_url) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14988 | NOTREACHED(); |
| 14989 | return NULL; |
| 14990 | }; |
| 14991 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14992 | ~FakeWebSocketStreamCreateHelper() override {} |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14993 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14994 | virtual std::unique_ptr<WebSocketStream> Upgrade() { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14995 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14996 | return std::unique_ptr<WebSocketStream>(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14997 | } |
| 14998 | }; |
| 14999 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15000 | } // namespace |
| 15001 | |
| 15002 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 15003 | // stream request on start. |
| 15004 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15005 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15006 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15007 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15008 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15009 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15010 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15011 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15012 | ASSERT_FALSE(fake_factory->last_stream_request()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15013 | |
| 15014 | HttpRequestInfo request; |
| 15015 | TestCompletionCallback callback; |
| 15016 | EXPECT_EQ(ERR_IO_PENDING, |
| 15017 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 15018 | |
| 15019 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15020 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15021 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15022 | EXPECT_EQ(LOW, fake_request->priority()); |
| 15023 | } |
| 15024 | |
| 15025 | // Make sure that HttpNetworkTransaction passes on its priority |
| 15026 | // updates to its stream request. |
| 15027 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15028 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15029 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15030 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15031 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15032 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15033 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15034 | |
| 15035 | HttpRequestInfo request; |
| 15036 | TestCompletionCallback callback; |
| 15037 | EXPECT_EQ(ERR_IO_PENDING, |
| 15038 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 15039 | |
| 15040 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15041 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15042 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15043 | EXPECT_EQ(LOW, fake_request->priority()); |
| 15044 | |
| 15045 | trans.SetPriority(LOWEST); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15046 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15047 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 15048 | } |
| 15049 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15050 | // Make sure that HttpNetworkTransaction passes on its priority |
| 15051 | // updates to its stream. |
| 15052 | TEST_P(HttpNetworkTransactionTest, SetStreamPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15053 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15054 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15055 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15056 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15057 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15058 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15059 | |
| 15060 | HttpRequestInfo request; |
| 15061 | TestCompletionCallback callback; |
| 15062 | EXPECT_EQ(ERR_IO_PENDING, |
| 15063 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 15064 | |
| 15065 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15066 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15067 | ASSERT_TRUE(fake_request); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15068 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15069 | ASSERT_TRUE(fake_stream); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15070 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 15071 | |
| 15072 | trans.SetPriority(LOWEST); |
| 15073 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 15074 | } |
| 15075 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15076 | TEST_P(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
| 15077 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 15078 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 15079 | // that the different schemes work. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15080 | std::string test_cases[] = {"ws://www.example.org/", |
| 15081 | "wss://www.example.org/"}; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15082 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15083 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15084 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15085 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 15086 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
[email protected] | 0191b51c | 2013-11-18 10:55:23 | [diff] [blame] | 15087 | peer.SetHttpStreamFactoryForWebSocket( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15088 | std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15089 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15090 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15091 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 15092 | &websocket_stream_create_helper); |
| 15093 | |
| 15094 | HttpRequestInfo request; |
| 15095 | TestCompletionCallback callback; |
| 15096 | request.method = "GET"; |
| 15097 | request.url = GURL(test_cases[i]); |
| 15098 | |
| 15099 | EXPECT_EQ(ERR_IO_PENDING, |
| 15100 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 15101 | |
| 15102 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15103 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15104 | ASSERT_TRUE(fake_request); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15105 | EXPECT_EQ(&websocket_stream_create_helper, |
| 15106 | fake_request->websocket_stream_create_helper()); |
| 15107 | } |
| 15108 | } |
| 15109 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15110 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 15111 | // if the transport socket pool is stalled on the global socket limit. |
| 15112 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
| 15113 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15114 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15115 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15116 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15117 | |
| 15118 | // Set up SSL request. |
| 15119 | |
| 15120 | HttpRequestInfo ssl_request; |
| 15121 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15122 | ssl_request.url = GURL("https://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15123 | |
| 15124 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15125 | MockWrite( |
| 15126 | "GET / HTTP/1.1\r\n" |
| 15127 | "Host: www.example.org\r\n" |
| 15128 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15129 | }; |
| 15130 | MockRead ssl_reads[] = { |
| 15131 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15132 | MockRead("Content-Length: 11\r\n\r\n"), |
| 15133 | MockRead("hello world"), |
| 15134 | MockRead(SYNCHRONOUS, OK), |
| 15135 | }; |
| 15136 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 15137 | ssl_writes, arraysize(ssl_writes)); |
| 15138 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 15139 | |
| 15140 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15141 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15142 | |
| 15143 | // Set up HTTP request. |
| 15144 | |
| 15145 | HttpRequestInfo http_request; |
| 15146 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15147 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15148 | |
| 15149 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15150 | MockWrite( |
| 15151 | "GET / HTTP/1.1\r\n" |
| 15152 | "Host: www.example.org\r\n" |
| 15153 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15154 | }; |
| 15155 | MockRead http_reads[] = { |
| 15156 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15157 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15158 | MockRead("falafel"), |
| 15159 | MockRead(SYNCHRONOUS, OK), |
| 15160 | }; |
| 15161 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15162 | http_writes, arraysize(http_writes)); |
| 15163 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15164 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15165 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15166 | |
| 15167 | // Start the SSL request. |
| 15168 | TestCompletionCallback ssl_callback; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15169 | std::unique_ptr<HttpTransaction> ssl_trans( |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15170 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15171 | ASSERT_EQ(ERR_IO_PENDING, |
| 15172 | ssl_trans->Start(&ssl_request, ssl_callback.callback(), |
| 15173 | BoundNetLog())); |
| 15174 | |
| 15175 | // Start the HTTP request. Pool should stall. |
| 15176 | TestCompletionCallback http_callback; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15177 | std::unique_ptr<HttpTransaction> http_trans( |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15178 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15179 | ASSERT_EQ(ERR_IO_PENDING, |
| 15180 | http_trans->Start(&http_request, http_callback.callback(), |
| 15181 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15182 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15183 | |
| 15184 | // Wait for response from SSL request. |
| 15185 | ASSERT_EQ(OK, ssl_callback.WaitForResult()); |
| 15186 | std::string response_data; |
| 15187 | ASSERT_EQ(OK, ReadTransaction(ssl_trans.get(), &response_data)); |
| 15188 | EXPECT_EQ("hello world", response_data); |
| 15189 | |
| 15190 | // The SSL socket should automatically be closed, so the HTTP request can |
| 15191 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15192 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 15193 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15194 | |
| 15195 | // The HTTP request can now complete. |
| 15196 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 15197 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 15198 | EXPECT_EQ("falafel", response_data); |
| 15199 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15200 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15201 | } |
| 15202 | |
| 15203 | // Tests that when a SSL connection is established but there's no corresponding |
| 15204 | // request that needs it, the new socket is closed if the transport socket pool |
| 15205 | // is stalled on the global socket limit. |
| 15206 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
| 15207 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15208 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15209 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15210 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15211 | |
| 15212 | // Set up an ssl request. |
| 15213 | |
| 15214 | HttpRequestInfo ssl_request; |
| 15215 | ssl_request.method = "GET"; |
| 15216 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 15217 | |
| 15218 | // No data will be sent on the SSL socket. |
| 15219 | StaticSocketDataProvider ssl_data; |
| 15220 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 15221 | |
| 15222 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15223 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15224 | |
| 15225 | // Set up HTTP request. |
| 15226 | |
| 15227 | HttpRequestInfo http_request; |
| 15228 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15229 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15230 | |
| 15231 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15232 | MockWrite( |
| 15233 | "GET / HTTP/1.1\r\n" |
| 15234 | "Host: www.example.org\r\n" |
| 15235 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15236 | }; |
| 15237 | MockRead http_reads[] = { |
| 15238 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15239 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15240 | MockRead("falafel"), |
| 15241 | MockRead(SYNCHRONOUS, OK), |
| 15242 | }; |
| 15243 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15244 | http_writes, arraysize(http_writes)); |
| 15245 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15246 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15247 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15248 | |
| 15249 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 15250 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15251 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 15252 | http_stream_factory->PreconnectStreams(1, ssl_request); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15253 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15254 | |
| 15255 | // Start the HTTP request. Pool should stall. |
| 15256 | TestCompletionCallback http_callback; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15257 | std::unique_ptr<HttpTransaction> http_trans( |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15258 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15259 | ASSERT_EQ(ERR_IO_PENDING, |
| 15260 | http_trans->Start(&http_request, http_callback.callback(), |
| 15261 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15262 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15263 | |
| 15264 | // The SSL connection will automatically be closed once the connection is |
| 15265 | // established, to let the HTTP request start. |
| 15266 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 15267 | std::string response_data; |
| 15268 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 15269 | EXPECT_EQ("falafel", response_data); |
| 15270 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15271 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15272 | } |
| 15273 | |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15274 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15275 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15276 | element_readers.push_back( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15277 | base::WrapUnique(new UploadBytesElementReader("foo", 3))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15278 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15279 | |
| 15280 | HttpRequestInfo request; |
| 15281 | request.method = "POST"; |
| 15282 | request.url = GURL("http://www.foo.com/"); |
| 15283 | request.upload_data_stream = &upload_data_stream; |
| 15284 | request.load_flags = 0; |
| 15285 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15286 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15287 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15288 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15289 | // Send headers successfully, but get an error while sending the body. |
| 15290 | MockWrite data_writes[] = { |
| 15291 | MockWrite("POST / HTTP/1.1\r\n" |
| 15292 | "Host: www.foo.com\r\n" |
| 15293 | "Connection: keep-alive\r\n" |
| 15294 | "Content-Length: 3\r\n\r\n"), |
| 15295 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15296 | }; |
| 15297 | |
| 15298 | MockRead data_reads[] = { |
| 15299 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15300 | MockRead("hello world"), |
| 15301 | MockRead(SYNCHRONOUS, OK), |
| 15302 | }; |
| 15303 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15304 | arraysize(data_writes)); |
| 15305 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15306 | |
| 15307 | TestCompletionCallback callback; |
| 15308 | |
| 15309 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15310 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15311 | |
| 15312 | rv = callback.WaitForResult(); |
| 15313 | EXPECT_EQ(OK, rv); |
| 15314 | |
| 15315 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15316 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15317 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15318 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15319 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15320 | |
| 15321 | std::string response_data; |
| 15322 | rv = ReadTransaction(trans.get(), &response_data); |
| 15323 | EXPECT_EQ(OK, rv); |
| 15324 | EXPECT_EQ("hello world", response_data); |
| 15325 | } |
| 15326 | |
| 15327 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 15328 | // response from a server that rejected a POST with a CONNECTION_RESET. |
| 15329 | TEST_P(HttpNetworkTransactionTest, |
| 15330 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15331 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15332 | MockWrite data_writes[] = { |
| 15333 | MockWrite("GET / HTTP/1.1\r\n" |
| 15334 | "Host: www.foo.com\r\n" |
| 15335 | "Connection: keep-alive\r\n\r\n"), |
| 15336 | MockWrite("POST / HTTP/1.1\r\n" |
| 15337 | "Host: www.foo.com\r\n" |
| 15338 | "Connection: keep-alive\r\n" |
| 15339 | "Content-Length: 3\r\n\r\n"), |
| 15340 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15341 | }; |
| 15342 | |
| 15343 | MockRead data_reads[] = { |
| 15344 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 15345 | "Content-Length: 14\r\n\r\n"), |
| 15346 | MockRead("first response"), |
| 15347 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 15348 | "Content-Length: 15\r\n\r\n"), |
| 15349 | MockRead("second response"), |
| 15350 | MockRead(SYNCHRONOUS, OK), |
| 15351 | }; |
| 15352 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15353 | arraysize(data_writes)); |
| 15354 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15355 | |
| 15356 | TestCompletionCallback callback; |
| 15357 | HttpRequestInfo request1; |
| 15358 | request1.method = "GET"; |
| 15359 | request1.url = GURL("http://www.foo.com/"); |
| 15360 | request1.load_flags = 0; |
| 15361 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15362 | std::unique_ptr<HttpTransaction> trans1( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15363 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15364 | int rv = trans1->Start(&request1, callback.callback(), BoundNetLog()); |
| 15365 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15366 | |
| 15367 | rv = callback.WaitForResult(); |
| 15368 | EXPECT_EQ(OK, rv); |
| 15369 | |
| 15370 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15371 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15372 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15373 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15374 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 15375 | |
| 15376 | std::string response_data1; |
| 15377 | rv = ReadTransaction(trans1.get(), &response_data1); |
| 15378 | EXPECT_EQ(OK, rv); |
| 15379 | EXPECT_EQ("first response", response_data1); |
| 15380 | // Delete the transaction to release the socket back into the socket pool. |
| 15381 | trans1.reset(); |
| 15382 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15383 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15384 | element_readers.push_back( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15385 | base::WrapUnique(new UploadBytesElementReader("foo", 3))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15386 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15387 | |
| 15388 | HttpRequestInfo request2; |
| 15389 | request2.method = "POST"; |
| 15390 | request2.url = GURL("http://www.foo.com/"); |
| 15391 | request2.upload_data_stream = &upload_data_stream; |
| 15392 | request2.load_flags = 0; |
| 15393 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15394 | std::unique_ptr<HttpTransaction> trans2( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15395 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15396 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 15397 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15398 | |
| 15399 | rv = callback.WaitForResult(); |
| 15400 | EXPECT_EQ(OK, rv); |
| 15401 | |
| 15402 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15403 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15404 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15405 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15406 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 15407 | |
| 15408 | std::string response_data2; |
| 15409 | rv = ReadTransaction(trans2.get(), &response_data2); |
| 15410 | EXPECT_EQ(OK, rv); |
| 15411 | EXPECT_EQ("second response", response_data2); |
| 15412 | } |
| 15413 | |
| 15414 | TEST_P(HttpNetworkTransactionTest, |
| 15415 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15416 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15417 | element_readers.push_back( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15418 | base::WrapUnique(new UploadBytesElementReader("foo", 3))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15419 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15420 | |
| 15421 | HttpRequestInfo request; |
| 15422 | request.method = "POST"; |
| 15423 | request.url = GURL("http://www.foo.com/"); |
| 15424 | request.upload_data_stream = &upload_data_stream; |
| 15425 | request.load_flags = 0; |
| 15426 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15427 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15428 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15429 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15430 | // Send headers successfully, but get an error while sending the body. |
| 15431 | MockWrite data_writes[] = { |
| 15432 | MockWrite("POST / HTTP/1.1\r\n" |
| 15433 | "Host: www.foo.com\r\n" |
| 15434 | "Connection: keep-alive\r\n" |
| 15435 | "Content-Length: 3\r\n\r\n" |
| 15436 | "fo"), |
| 15437 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15438 | }; |
| 15439 | |
| 15440 | MockRead data_reads[] = { |
| 15441 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15442 | MockRead("hello world"), |
| 15443 | MockRead(SYNCHRONOUS, OK), |
| 15444 | }; |
| 15445 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15446 | arraysize(data_writes)); |
| 15447 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15448 | |
| 15449 | TestCompletionCallback callback; |
| 15450 | |
| 15451 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15452 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15453 | |
| 15454 | rv = callback.WaitForResult(); |
| 15455 | EXPECT_EQ(OK, rv); |
| 15456 | |
| 15457 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15458 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15459 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15460 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15461 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15462 | |
| 15463 | std::string response_data; |
| 15464 | rv = ReadTransaction(trans.get(), &response_data); |
| 15465 | EXPECT_EQ(OK, rv); |
| 15466 | EXPECT_EQ("hello world", response_data); |
| 15467 | } |
| 15468 | |
| 15469 | // This tests the more common case than the previous test, where headers and |
| 15470 | // body are not merged into a single request. |
| 15471 | TEST_P(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 15472 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15473 | |
| 15474 | HttpRequestInfo request; |
| 15475 | request.method = "POST"; |
| 15476 | request.url = GURL("http://www.foo.com/"); |
| 15477 | request.upload_data_stream = &upload_data_stream; |
| 15478 | request.load_flags = 0; |
| 15479 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15480 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15481 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15482 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15483 | // Send headers successfully, but get an error while sending the body. |
| 15484 | MockWrite data_writes[] = { |
| 15485 | MockWrite("POST / HTTP/1.1\r\n" |
| 15486 | "Host: www.foo.com\r\n" |
| 15487 | "Connection: keep-alive\r\n" |
| 15488 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 15489 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15490 | }; |
| 15491 | |
| 15492 | MockRead data_reads[] = { |
| 15493 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15494 | MockRead("hello world"), |
| 15495 | MockRead(SYNCHRONOUS, OK), |
| 15496 | }; |
| 15497 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15498 | arraysize(data_writes)); |
| 15499 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15500 | |
| 15501 | TestCompletionCallback callback; |
| 15502 | |
| 15503 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15504 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15505 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 15506 | // they can't be merged with the body in a single send. Not currently |
| 15507 | // necessary since a chunked body is never merged with headers, but this makes |
| 15508 | // the test more future proof. |
| 15509 | base::RunLoop().RunUntilIdle(); |
| 15510 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 15511 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15512 | |
| 15513 | rv = callback.WaitForResult(); |
| 15514 | EXPECT_EQ(OK, rv); |
| 15515 | |
| 15516 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15517 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15518 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15519 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15520 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15521 | |
| 15522 | std::string response_data; |
| 15523 | rv = ReadTransaction(trans.get(), &response_data); |
| 15524 | EXPECT_EQ(OK, rv); |
| 15525 | EXPECT_EQ("hello world", response_data); |
| 15526 | } |
| 15527 | |
| 15528 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15529 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15530 | element_readers.push_back( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15531 | base::WrapUnique(new UploadBytesElementReader("foo", 3))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15532 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15533 | |
| 15534 | HttpRequestInfo request; |
| 15535 | request.method = "POST"; |
| 15536 | request.url = GURL("http://www.foo.com/"); |
| 15537 | request.upload_data_stream = &upload_data_stream; |
| 15538 | request.load_flags = 0; |
| 15539 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15540 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15541 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15542 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15543 | |
| 15544 | MockWrite data_writes[] = { |
| 15545 | MockWrite("POST / HTTP/1.1\r\n" |
| 15546 | "Host: www.foo.com\r\n" |
| 15547 | "Connection: keep-alive\r\n" |
| 15548 | "Content-Length: 3\r\n\r\n"), |
| 15549 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15550 | }; |
| 15551 | |
| 15552 | MockRead data_reads[] = { |
| 15553 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 15554 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15555 | MockRead("hello world"), |
| 15556 | MockRead(SYNCHRONOUS, OK), |
| 15557 | }; |
| 15558 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15559 | arraysize(data_writes)); |
| 15560 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15561 | |
| 15562 | TestCompletionCallback callback; |
| 15563 | |
| 15564 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15565 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15566 | |
| 15567 | rv = callback.WaitForResult(); |
| 15568 | EXPECT_EQ(OK, rv); |
| 15569 | |
| 15570 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15571 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15572 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15573 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15574 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15575 | |
| 15576 | std::string response_data; |
| 15577 | rv = ReadTransaction(trans.get(), &response_data); |
| 15578 | EXPECT_EQ(OK, rv); |
| 15579 | EXPECT_EQ("hello world", response_data); |
| 15580 | } |
| 15581 | |
| 15582 | TEST_P(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15583 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15584 | element_readers.push_back( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15585 | base::WrapUnique(new UploadBytesElementReader("foo", 3))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15586 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15587 | |
| 15588 | HttpRequestInfo request; |
| 15589 | request.method = "POST"; |
| 15590 | request.url = GURL("http://www.foo.com/"); |
| 15591 | request.upload_data_stream = &upload_data_stream; |
| 15592 | request.load_flags = 0; |
| 15593 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15594 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15595 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15596 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15597 | // Send headers successfully, but get an error while sending the body. |
| 15598 | MockWrite data_writes[] = { |
| 15599 | MockWrite("POST / HTTP/1.1\r\n" |
| 15600 | "Host: www.foo.com\r\n" |
| 15601 | "Connection: keep-alive\r\n" |
| 15602 | "Content-Length: 3\r\n\r\n"), |
| 15603 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15604 | }; |
| 15605 | |
| 15606 | MockRead data_reads[] = { |
| 15607 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 15608 | MockRead("hello world"), |
| 15609 | MockRead(SYNCHRONOUS, OK), |
| 15610 | }; |
| 15611 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15612 | arraysize(data_writes)); |
| 15613 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15614 | |
| 15615 | TestCompletionCallback callback; |
| 15616 | |
| 15617 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15618 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15619 | |
| 15620 | rv = callback.WaitForResult(); |
| 15621 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15622 | } |
| 15623 | |
| 15624 | TEST_P(HttpNetworkTransactionTest, |
| 15625 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15626 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15627 | element_readers.push_back( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15628 | base::WrapUnique(new UploadBytesElementReader("foo", 3))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15629 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15630 | |
| 15631 | HttpRequestInfo request; |
| 15632 | request.method = "POST"; |
| 15633 | request.url = GURL("http://www.foo.com/"); |
| 15634 | request.upload_data_stream = &upload_data_stream; |
| 15635 | request.load_flags = 0; |
| 15636 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15637 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15638 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15639 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15640 | // Send headers successfully, but get an error while sending the body. |
| 15641 | MockWrite data_writes[] = { |
| 15642 | MockWrite("POST / HTTP/1.1\r\n" |
| 15643 | "Host: www.foo.com\r\n" |
| 15644 | "Connection: keep-alive\r\n" |
| 15645 | "Content-Length: 3\r\n\r\n"), |
| 15646 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15647 | }; |
| 15648 | |
| 15649 | MockRead data_reads[] = { |
| 15650 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 15651 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 15652 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 15653 | MockRead("Content-Length: 0\r\n\r\n"), |
| 15654 | MockRead(SYNCHRONOUS, OK), |
| 15655 | }; |
| 15656 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15657 | arraysize(data_writes)); |
| 15658 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15659 | |
| 15660 | TestCompletionCallback callback; |
| 15661 | |
| 15662 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15663 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15664 | |
| 15665 | rv = callback.WaitForResult(); |
| 15666 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15667 | } |
| 15668 | |
| 15669 | TEST_P(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15670 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15671 | element_readers.push_back( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15672 | base::WrapUnique(new UploadBytesElementReader("foo", 3))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15673 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15674 | |
| 15675 | HttpRequestInfo request; |
| 15676 | request.method = "POST"; |
| 15677 | request.url = GURL("http://www.foo.com/"); |
| 15678 | request.upload_data_stream = &upload_data_stream; |
| 15679 | request.load_flags = 0; |
| 15680 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15681 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15682 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15683 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15684 | // Send headers successfully, but get an error while sending the body. |
| 15685 | MockWrite data_writes[] = { |
| 15686 | MockWrite("POST / HTTP/1.1\r\n" |
| 15687 | "Host: www.foo.com\r\n" |
| 15688 | "Connection: keep-alive\r\n" |
| 15689 | "Content-Length: 3\r\n\r\n"), |
| 15690 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15691 | }; |
| 15692 | |
| 15693 | MockRead data_reads[] = { |
| 15694 | MockRead("HTTP 0.9 rocks!"), |
| 15695 | MockRead(SYNCHRONOUS, OK), |
| 15696 | }; |
| 15697 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15698 | arraysize(data_writes)); |
| 15699 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15700 | |
| 15701 | TestCompletionCallback callback; |
| 15702 | |
| 15703 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15704 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15705 | |
| 15706 | rv = callback.WaitForResult(); |
| 15707 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15708 | } |
| 15709 | |
| 15710 | TEST_P(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15711 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15712 | element_readers.push_back( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15713 | base::WrapUnique(new UploadBytesElementReader("foo", 3))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15714 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15715 | |
| 15716 | HttpRequestInfo request; |
| 15717 | request.method = "POST"; |
| 15718 | request.url = GURL("http://www.foo.com/"); |
| 15719 | request.upload_data_stream = &upload_data_stream; |
| 15720 | request.load_flags = 0; |
| 15721 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15722 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15723 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15724 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15725 | // Send headers successfully, but get an error while sending the body. |
| 15726 | MockWrite data_writes[] = { |
| 15727 | MockWrite("POST / HTTP/1.1\r\n" |
| 15728 | "Host: www.foo.com\r\n" |
| 15729 | "Connection: keep-alive\r\n" |
| 15730 | "Content-Length: 3\r\n\r\n"), |
| 15731 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15732 | }; |
| 15733 | |
| 15734 | MockRead data_reads[] = { |
| 15735 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 15736 | MockRead(SYNCHRONOUS, OK), |
| 15737 | }; |
| 15738 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15739 | arraysize(data_writes)); |
| 15740 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15741 | |
| 15742 | TestCompletionCallback callback; |
| 15743 | |
| 15744 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15745 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15746 | |
| 15747 | rv = callback.WaitForResult(); |
| 15748 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15749 | } |
| 15750 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15751 | // Verify that proxy headers are not sent to the destination server when |
| 15752 | // establishing a tunnel for a secure WebSocket connection. |
| 15753 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
| 15754 | HttpRequestInfo request; |
| 15755 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15756 | request.url = GURL("wss://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15757 | AddWebSocketHeaders(&request.extra_headers); |
| 15758 | |
| 15759 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 15760 | session_deps_.proxy_service = |
| 15761 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15762 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15763 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15764 | |
| 15765 | // Since a proxy is configured, try to establish a tunnel. |
| 15766 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15767 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15768 | "Host: www.example.org:443\r\n" |
| 15769 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15770 | |
| 15771 | // After calling trans->RestartWithAuth(), this is the request we should |
| 15772 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15773 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15774 | "Host: www.example.org:443\r\n" |
| 15775 | "Proxy-Connection: keep-alive\r\n" |
| 15776 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15777 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15778 | MockWrite("GET / HTTP/1.1\r\n" |
| 15779 | "Host: www.example.org\r\n" |
| 15780 | "Connection: Upgrade\r\n" |
| 15781 | "Upgrade: websocket\r\n" |
| 15782 | "Origin: http://www.example.org\r\n" |
| 15783 | "Sec-WebSocket-Version: 13\r\n" |
| 15784 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15785 | }; |
| 15786 | |
| 15787 | // The proxy responds to the connect with a 407, using a persistent |
| 15788 | // connection. |
| 15789 | MockRead data_reads[] = { |
| 15790 | // No credentials. |
| 15791 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 15792 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 15793 | MockRead("Content-Length: 0\r\n"), |
| 15794 | MockRead("Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15795 | |
| 15796 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 15797 | |
| 15798 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 15799 | MockRead("Upgrade: websocket\r\n"), |
| 15800 | MockRead("Connection: Upgrade\r\n"), |
| 15801 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 15802 | }; |
| 15803 | |
| 15804 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15805 | arraysize(data_writes)); |
| 15806 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15807 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15808 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15809 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15810 | std::unique_ptr<HttpTransaction> trans( |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15811 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15812 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 15813 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 15814 | &websocket_stream_create_helper); |
| 15815 | |
| 15816 | { |
| 15817 | TestCompletionCallback callback; |
| 15818 | |
| 15819 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15820 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15821 | |
| 15822 | rv = callback.WaitForResult(); |
| 15823 | EXPECT_EQ(OK, rv); |
| 15824 | } |
| 15825 | |
| 15826 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15827 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15828 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15829 | EXPECT_EQ(407, response->headers->response_code()); |
| 15830 | |
| 15831 | { |
| 15832 | TestCompletionCallback callback; |
| 15833 | |
| 15834 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 15835 | callback.callback()); |
| 15836 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15837 | |
| 15838 | rv = callback.WaitForResult(); |
| 15839 | EXPECT_EQ(OK, rv); |
| 15840 | } |
| 15841 | |
| 15842 | response = trans->GetResponseInfo(); |
| 15843 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15844 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15845 | |
| 15846 | EXPECT_EQ(101, response->headers->response_code()); |
| 15847 | |
| 15848 | trans.reset(); |
| 15849 | session->CloseAllConnections(); |
| 15850 | } |
| 15851 | |
| 15852 | // Verify that proxy headers are not sent to the destination server when |
| 15853 | // establishing a tunnel for an insecure WebSocket connection. |
| 15854 | // This requires the authentication info to be injected into the auth cache |
| 15855 | // due to crbug.com/395064 |
| 15856 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
| 15857 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
| 15858 | HttpRequestInfo request; |
| 15859 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15860 | request.url = GURL("ws://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15861 | AddWebSocketHeaders(&request.extra_headers); |
| 15862 | |
| 15863 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 15864 | session_deps_.proxy_service = |
| 15865 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15866 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15867 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15868 | |
| 15869 | MockWrite data_writes[] = { |
| 15870 | // Try to establish a tunnel for the WebSocket connection, with |
| 15871 | // credentials. Because WebSockets have a separate set of socket pools, |
| 15872 | // they cannot and will not use the same TCP/IP connection as the |
| 15873 | // preflight HTTP request. |
| 15874 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15875 | "CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 15876 | "Host: www.example.org:80\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15877 | "Proxy-Connection: keep-alive\r\n" |
| 15878 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 15879 | |
| 15880 | MockWrite( |
| 15881 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15882 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15883 | "Connection: Upgrade\r\n" |
| 15884 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15885 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15886 | "Sec-WebSocket-Version: 13\r\n" |
| 15887 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 15888 | }; |
| 15889 | |
| 15890 | MockRead data_reads[] = { |
| 15891 | // HTTP CONNECT with credentials. |
| 15892 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 15893 | |
| 15894 | // WebSocket connection established inside tunnel. |
| 15895 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 15896 | MockRead("Upgrade: websocket\r\n"), |
| 15897 | MockRead("Connection: Upgrade\r\n"), |
| 15898 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 15899 | }; |
| 15900 | |
| 15901 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15902 | arraysize(data_writes)); |
| 15903 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15904 | |
| 15905 | session->http_auth_cache()->Add( |
| 15906 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 15907 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 15908 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15909 | std::unique_ptr<HttpTransaction> trans( |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15910 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15911 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 15912 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 15913 | &websocket_stream_create_helper); |
| 15914 | |
| 15915 | TestCompletionCallback callback; |
| 15916 | |
| 15917 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15918 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15919 | |
| 15920 | rv = callback.WaitForResult(); |
| 15921 | EXPECT_EQ(OK, rv); |
| 15922 | |
| 15923 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15924 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15925 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15926 | |
| 15927 | EXPECT_EQ(101, response->headers->response_code()); |
| 15928 | |
| 15929 | trans.reset(); |
| 15930 | session->CloseAllConnections(); |
| 15931 | } |
| 15932 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15933 | TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15934 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15935 | element_readers.push_back( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15936 | base::WrapUnique(new UploadBytesElementReader("foo", 3))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15937 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15938 | |
| 15939 | HttpRequestInfo request; |
| 15940 | request.method = "POST"; |
| 15941 | request.url = GURL("http://www.foo.com/"); |
| 15942 | request.upload_data_stream = &upload_data_stream; |
| 15943 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15944 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15945 | std::unique_ptr<HttpTransaction> trans( |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15946 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15947 | MockWrite data_writes[] = { |
| 15948 | MockWrite("POST / HTTP/1.1\r\n" |
| 15949 | "Host: www.foo.com\r\n" |
| 15950 | "Connection: keep-alive\r\n" |
| 15951 | "Content-Length: 3\r\n\r\n"), |
| 15952 | MockWrite("foo"), |
| 15953 | }; |
| 15954 | |
| 15955 | MockRead data_reads[] = { |
| 15956 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 15957 | MockRead(SYNCHRONOUS, OK), |
| 15958 | }; |
| 15959 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15960 | arraysize(data_writes)); |
| 15961 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15962 | |
| 15963 | TestCompletionCallback callback; |
| 15964 | |
| 15965 | EXPECT_EQ(ERR_IO_PENDING, |
| 15966 | trans->Start(&request, callback.callback(), BoundNetLog())); |
| 15967 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 15968 | |
| 15969 | std::string response_data; |
| 15970 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 15971 | |
| 15972 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 15973 | trans->GetTotalSentBytes()); |
| 15974 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 15975 | trans->GetTotalReceivedBytes()); |
| 15976 | } |
| 15977 | |
| 15978 | TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15979 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15980 | element_readers.push_back( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15981 | base::WrapUnique(new UploadBytesElementReader("foo", 3))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15982 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15983 | |
| 15984 | HttpRequestInfo request; |
| 15985 | request.method = "POST"; |
| 15986 | request.url = GURL("http://www.foo.com/"); |
| 15987 | request.upload_data_stream = &upload_data_stream; |
| 15988 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15989 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15990 | std::unique_ptr<HttpTransaction> trans( |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15991 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15992 | MockWrite data_writes[] = { |
| 15993 | MockWrite("POST / HTTP/1.1\r\n" |
| 15994 | "Host: www.foo.com\r\n" |
| 15995 | "Connection: keep-alive\r\n" |
| 15996 | "Content-Length: 3\r\n\r\n"), |
| 15997 | MockWrite("foo"), |
| 15998 | }; |
| 15999 | |
| 16000 | MockRead data_reads[] = { |
| 16001 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 16002 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16003 | MockRead(SYNCHRONOUS, OK), |
| 16004 | }; |
| 16005 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16006 | arraysize(data_writes)); |
| 16007 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16008 | |
| 16009 | TestCompletionCallback callback; |
| 16010 | |
| 16011 | EXPECT_EQ(ERR_IO_PENDING, |
| 16012 | trans->Start(&request, callback.callback(), BoundNetLog())); |
| 16013 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16014 | |
| 16015 | std::string response_data; |
| 16016 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 16017 | |
| 16018 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 16019 | trans->GetTotalSentBytes()); |
| 16020 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 16021 | trans->GetTotalReceivedBytes()); |
| 16022 | } |
| 16023 | |
| 16024 | TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16025 | ChunkedUploadDataStream upload_data_stream(0); |
| 16026 | |
| 16027 | HttpRequestInfo request; |
| 16028 | request.method = "POST"; |
| 16029 | request.url = GURL("http://www.foo.com/"); |
| 16030 | request.upload_data_stream = &upload_data_stream; |
| 16031 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16032 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 16033 | std::unique_ptr<HttpTransaction> trans( |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16034 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 16035 | // Send headers successfully, but get an error while sending the body. |
| 16036 | MockWrite data_writes[] = { |
| 16037 | MockWrite("POST / HTTP/1.1\r\n" |
| 16038 | "Host: www.foo.com\r\n" |
| 16039 | "Connection: keep-alive\r\n" |
| 16040 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 16041 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 16042 | }; |
| 16043 | |
| 16044 | MockRead data_reads[] = { |
| 16045 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16046 | MockRead(SYNCHRONOUS, OK), |
| 16047 | }; |
| 16048 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16049 | arraysize(data_writes)); |
| 16050 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16051 | |
| 16052 | TestCompletionCallback callback; |
| 16053 | |
| 16054 | EXPECT_EQ(ERR_IO_PENDING, |
| 16055 | trans->Start(&request, callback.callback(), BoundNetLog())); |
| 16056 | |
| 16057 | base::RunLoop().RunUntilIdle(); |
| 16058 | upload_data_stream.AppendData("f", 1, false); |
| 16059 | |
| 16060 | base::RunLoop().RunUntilIdle(); |
| 16061 | upload_data_stream.AppendData("oo", 2, true); |
| 16062 | |
| 16063 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16064 | |
| 16065 | std::string response_data; |
| 16066 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 16067 | |
| 16068 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 16069 | trans->GetTotalSentBytes()); |
| 16070 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 16071 | trans->GetTotalReceivedBytes()); |
| 16072 | } |
| 16073 | |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 16074 | TEST_P(HttpNetworkTransactionTest, EnableNPN) { |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 16075 | session_deps_.enable_npn = true; |
| 16076 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16077 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 16078 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 16079 | HttpRequestInfo request; |
| 16080 | TestCompletionCallback callback; |
| 16081 | EXPECT_EQ(ERR_IO_PENDING, |
| 16082 | trans.Start(&request, callback.callback(), BoundNetLog())); |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 16083 | |
| 16084 | EXPECT_THAT(trans.server_ssl_config_.alpn_protos, |
| 16085 | testing::ElementsAre(kProtoHTTP2, kProtoSPDY31, kProtoHTTP11)); |
| 16086 | EXPECT_THAT(trans.server_ssl_config_.npn_protos, |
| 16087 | testing::ElementsAre(kProtoHTTP2, kProtoSPDY31, kProtoHTTP11)); |
| 16088 | } |
| 16089 | |
| 16090 | TEST_P(HttpNetworkTransactionTest, DisableNPN) { |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 16091 | session_deps_.enable_npn = false; |
| 16092 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16093 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 16094 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 16095 | HttpRequestInfo request; |
| 16096 | TestCompletionCallback callback; |
| 16097 | EXPECT_EQ(ERR_IO_PENDING, |
| 16098 | trans.Start(&request, callback.callback(), BoundNetLog())); |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 16099 | |
| 16100 | EXPECT_THAT(trans.server_ssl_config_.alpn_protos, |
| 16101 | testing::ElementsAre(kProtoHTTP2, kProtoSPDY31, kProtoHTTP11)); |
| 16102 | EXPECT_TRUE(trans.server_ssl_config_.npn_protos.empty()); |
| 16103 | } |
| 16104 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16105 | #if !defined(OS_IOS) |
| 16106 | TEST_P(HttpNetworkTransactionTest, TokenBindingSpdy) { |
| 16107 | const std::string https_url = "https://www.example.com"; |
| 16108 | HttpRequestInfo request; |
| 16109 | request.url = GURL(https_url); |
| 16110 | request.method = "GET"; |
| 16111 | |
| 16112 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16113 | ssl.token_binding_negotiated = true; |
| 16114 | ssl.token_binding_key_param = TB_PARAM_ECDSAP256; |
| 16115 | ssl.SetNextProto(GetProtocol()); |
| 16116 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16117 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16118 | std::unique_ptr<SpdySerializedFrame> resp( |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16119 | spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16120 | std::unique_ptr<SpdySerializedFrame> body( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 16121 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16122 | MockRead reads[] = {CreateMockRead(*resp), CreateMockRead(*body), |
| 16123 | MockRead(ASYNC, ERR_IO_PENDING)}; |
| 16124 | StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); |
| 16125 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16126 | session_deps_.channel_id_service.reset(new ChannelIDService( |
| 16127 | new DefaultChannelIDStore(nullptr), base::ThreadTaskRunnerHandle::Get())); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16128 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16129 | |
| 16130 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 16131 | TestCompletionCallback callback; |
| 16132 | EXPECT_EQ(ERR_IO_PENDING, |
| 16133 | trans.Start(&request, callback.callback(), BoundNetLog())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 16134 | base::RunLoop().RunUntilIdle(); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16135 | |
| 16136 | EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| 16137 | HttpRequestHeaders headers; |
| 16138 | ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
| 16139 | EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 16140 | } |
| 16141 | #endif // !defined(OS_IOS) |
| 16142 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 16143 | } // namespace net |