[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> |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 12 | #include <set> |
[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" |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 22 | #include "base/memory/ptr_util.h" |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 23 | #include "base/memory/weak_ptr.h" |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 24 | #include "base/run_loop.h" |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 25 | #include "base/stl_util.h" |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 26 | #include "base/strings/string_piece.h" |
[email protected] | 125ef48 | 2013-06-11 18:32:47 | [diff] [blame] | 27 | #include "base/strings/string_util.h" |
[email protected] | 750b2f3c | 2013-06-07 18:41:05 | [diff] [blame] | 28 | #include "base/strings/utf_string_conversions.h" |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 29 | #include "base/test/metrics/histogram_tester.h" |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 30 | #include "base/test/simple_test_clock.h" |
| 31 | #include "base/test/simple_test_tick_clock.h" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 32 | #include "base/test/test_file_util.h" |
gab | f767595f | 2016-05-11 18:50:35 | [diff] [blame] | 33 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 34 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 35 | #include "net/base/chunked_upload_data_stream.h" |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 36 | #include "net/base/completion_once_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 37 | #include "net/base/elements_upload_data_stream.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 38 | #include "net/base/load_timing_info.h" |
| 39 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 40 | #include "net/base/net_errors.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 41 | #include "net/base/proxy_delegate.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 42 | #include "net/base/proxy_server.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 43 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 44 | #include "net/base/test_completion_callback.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 45 | #include "net/base/test_proxy_delegate.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 46 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 47 | #include "net/base/upload_file_element_reader.h" |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 48 | #include "net/cert/cert_status_flags.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 49 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 50 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 51 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 52 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 53 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 54 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 55 | #include "net/http/http_auth_handler_ntlm.h" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 56 | #include "net/http/http_auth_scheme.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 57 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 58 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 59 | #include "net/http/http_network_session_peer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 60 | #include "net/http/http_request_headers.h" |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 61 | #include "net/http/http_response_info.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 62 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 63 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 64 | #include "net/http/http_stream_factory.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 65 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 66 | #include "net/log/net_log.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 67 | #include "net/log/net_log_event_type.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 68 | #include "net/log/net_log_source.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 69 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 70 | #include "net/log/test_net_log_entry.h" |
| 71 | #include "net/log/test_net_log_util.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 72 | #include "net/proxy_resolution/mock_proxy_resolver.h" |
| 73 | #include "net/proxy_resolution/proxy_config_service_fixed.h" |
| 74 | #include "net/proxy_resolution/proxy_info.h" |
Lily Houghton | ffe89daa0 | 2018-03-09 18:30:03 | [diff] [blame] | 75 | #include "net/proxy_resolution/proxy_resolution_service.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 76 | #include "net/proxy_resolution/proxy_resolver.h" |
| 77 | #include "net/proxy_resolution/proxy_resolver_factory.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 78 | #include "net/socket/client_socket_factory.h" |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 79 | #include "net/socket/client_socket_pool.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 80 | #include "net/socket/client_socket_pool_manager.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 81 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 82 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 83 | #include "net/socket/next_proto.h" |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 84 | #include "net/socket/socket_tag.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 85 | #include "net/socket/socket_test_util.h" |
| 86 | #include "net/socket/ssl_client_socket.h" |
Bence Béky | 94658bf | 2018-05-11 19:22:58 | [diff] [blame] | 87 | #include "net/spdy/spdy_session.h" |
| 88 | #include "net/spdy/spdy_session_pool.h" |
| 89 | #include "net/spdy/spdy_test_util_common.h" |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 90 | #include "net/ssl/default_channel_id_store.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 91 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 92 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 93 | #include "net/ssl/ssl_info.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 94 | #include "net/ssl/ssl_private_key.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 95 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 96 | #include "net/test/gtest_util.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 97 | #include "net/test/test_data_directory.h" |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 98 | #include "net/test/test_with_scoped_task_environment.h" |
Victor Vasiliev | 27cc771 | 2019-01-24 11:50:14 | [diff] [blame] | 99 | #include "net/third_party/quiche/src/spdy/core/spdy_framer.h" |
[email protected] | baee31a | 2018-01-18 06:10:23 | [diff] [blame] | 100 | #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 101 | #include "net/websockets/websocket_handshake_stream_base.h" |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 102 | #include "net/websockets/websocket_test_util.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 103 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 104 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 105 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 106 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 107 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 108 | #if defined(NTLM_PORTABLE) |
| 109 | #include "base/base64.h" |
| 110 | #include "net/ntlm/ntlm_test_data.h" |
| 111 | #endif |
| 112 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 113 | #if BUILDFLAG(ENABLE_REPORTING) |
| 114 | #include "net/network_error_logging/network_error_logging_service.h" |
| 115 | #include "net/network_error_logging/network_error_logging_test_util.h" |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 116 | #include "net/reporting/reporting_cache.h" |
| 117 | #include "net/reporting/reporting_client.h" |
| 118 | #include "net/reporting/reporting_header_parser.h" |
| 119 | #include "net/reporting/reporting_service.h" |
| 120 | #include "net/reporting/reporting_test_util.h" |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 121 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 122 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 123 | using net::test::IsError; |
| 124 | using net::test::IsOk; |
| 125 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 126 | using base::ASCIIToUTF16; |
| 127 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 128 | //----------------------------------------------------------------------------- |
| 129 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 130 | namespace net { |
| 131 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 132 | namespace { |
| 133 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 134 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 135 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 136 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 137 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 138 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 139 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 140 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 141 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 142 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 143 | const base::string16 kSecond(ASCIIToUTF16("second")); |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 144 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 145 | |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 146 | const char kAlternativeServiceHttpHeader[] = |
| 147 | "Alt-Svc: h2=\"mail.example.org:443\"\r\n"; |
| 148 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 149 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
| 150 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 151 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 152 | } |
| 153 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 154 | int GetIdleSocketCountInSSLSocketPool(HttpNetworkSession* session) { |
| 155 | return session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 156 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 157 | } |
| 158 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 159 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
| 160 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 161 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 162 | } |
| 163 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 164 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 165 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 166 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 167 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 168 | if (!params) |
| 169 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 170 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 171 | if (!params->GetList("headers", &header_list)) |
| 172 | return false; |
| 173 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 174 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 175 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 176 | return true; |
| 177 | } |
| 178 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 179 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 180 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 181 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 182 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 183 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 184 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 185 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 186 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 187 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 188 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 189 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 190 | |
| 191 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 192 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 193 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 194 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 195 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 196 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 197 | } |
| 198 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 199 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 200 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 201 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 202 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 203 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 204 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 205 | |
| 206 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 207 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 208 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 209 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 210 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 211 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 212 | load_timing_info.send_start); |
| 213 | |
| 214 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 215 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 216 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 217 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 218 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 219 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 223 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 224 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 225 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 226 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 227 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 228 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 229 | |
| 230 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 231 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 232 | load_timing_info.proxy_resolve_end); |
| 233 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 234 | load_timing_info.send_start); |
| 235 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 236 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 237 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 238 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 239 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 240 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 244 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 245 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 246 | int connect_timing_flags) { |
| 247 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 248 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 249 | |
| 250 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 251 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 252 | load_timing_info.proxy_resolve_end); |
| 253 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 254 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 255 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 256 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 257 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 258 | load_timing_info.send_start); |
| 259 | |
| 260 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 261 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 262 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 263 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 264 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 265 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 266 | } |
| 267 | |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 268 | // ProxyResolver that records URLs passed to it, and that can be told what |
| 269 | // result to return. |
| 270 | class CapturingProxyResolver : public ProxyResolver { |
| 271 | public: |
| 272 | CapturingProxyResolver() |
| 273 | : proxy_server_(ProxyServer::SCHEME_HTTP, HostPortPair("myproxy", 80)) {} |
| 274 | ~CapturingProxyResolver() override = default; |
| 275 | |
| 276 | int GetProxyForURL(const GURL& url, |
| 277 | ProxyInfo* results, |
| 278 | CompletionOnceCallback callback, |
| 279 | std::unique_ptr<Request>* request, |
| 280 | const NetLogWithSource& net_log) override { |
| 281 | results->UseProxyServer(proxy_server_); |
| 282 | resolved_.push_back(url); |
| 283 | return OK; |
| 284 | } |
| 285 | |
| 286 | // Sets whether the resolver should use direct connections, instead of a |
| 287 | // proxy. |
| 288 | void set_proxy_server(ProxyServer proxy_server) { |
| 289 | proxy_server_ = proxy_server; |
| 290 | } |
| 291 | |
| 292 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 293 | |
| 294 | private: |
| 295 | std::vector<GURL> resolved_; |
| 296 | |
| 297 | ProxyServer proxy_server_; |
| 298 | |
| 299 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 300 | }; |
| 301 | |
| 302 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 303 | public: |
| 304 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 305 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 306 | |
| 307 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 308 | std::unique_ptr<ProxyResolver>* resolver, |
| 309 | CompletionOnceCallback callback, |
| 310 | std::unique_ptr<Request>* request) override { |
| 311 | *resolver = std::make_unique<ForwardingProxyResolver>(resolver_); |
| 312 | return OK; |
| 313 | } |
| 314 | |
| 315 | private: |
| 316 | ProxyResolver* resolver_; |
| 317 | }; |
| 318 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 319 | std::unique_ptr<HttpNetworkSession> CreateSession( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 320 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 321 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 322 | } |
| 323 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 324 | class FailingProxyResolverFactory : public ProxyResolverFactory { |
| 325 | public: |
| 326 | FailingProxyResolverFactory() : ProxyResolverFactory(false) {} |
| 327 | |
| 328 | // ProxyResolverFactory override. |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 329 | int CreateProxyResolver(const scoped_refptr<PacFileData>& script_data, |
| 330 | std::unique_ptr<ProxyResolver>* result, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 331 | CompletionOnceCallback callback, |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 332 | std::unique_ptr<Request>* request) override { |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 333 | return ERR_PAC_SCRIPT_FAILED; |
| 334 | } |
| 335 | }; |
| 336 | |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 337 | class TestSSLConfigService : public SSLConfigService { |
| 338 | public: |
| 339 | explicit TestSSLConfigService(const SSLConfig& config) : config_(config) {} |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 340 | ~TestSSLConfigService() override = default; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 341 | |
| 342 | void GetSSLConfig(SSLConfig* config) override { *config = config_; } |
| 343 | |
Nick Harper | 89bc721 | 2018-07-31 19:07:57 | [diff] [blame] | 344 | bool CanShareConnectionWithClientCerts( |
| 345 | const std::string& hostname) const override { |
| 346 | return false; |
| 347 | } |
| 348 | |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 349 | private: |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 350 | SSLConfig config_; |
| 351 | }; |
| 352 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 353 | } // namespace |
| 354 | |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 355 | class HttpNetworkTransactionTest : public PlatformTest, |
| 356 | public WithScopedTaskEnvironment { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 357 | public: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 358 | ~HttpNetworkTransactionTest() override { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 359 | // Important to restore the per-pool limit first, since the pool limit must |
| 360 | // always be greater than group limit, and the tests reduce both limits. |
| 361 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 362 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 363 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 364 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 365 | } |
| 366 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 367 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 368 | HttpNetworkTransactionTest() |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 369 | : WithScopedTaskEnvironment( |
| 370 | base::test::ScopedTaskEnvironment::MainThreadType::IO_MOCK_TIME, |
| 371 | base::test::ScopedTaskEnvironment::NowSource:: |
| 372 | MAIN_THREAD_MOCK_TIME), |
| 373 | ssl_(ASYNC, OK), |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 374 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 375 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 376 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 377 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 378 | session_deps_.enable_http2_alternative_service = true; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 379 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 380 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 381 | struct SimpleGetHelperResult { |
| 382 | int rv; |
| 383 | std::string status_line; |
| 384 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 385 | int64_t total_received_bytes; |
| 386 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 387 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 388 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 389 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 390 | }; |
| 391 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 392 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 393 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 394 | base::RunLoop().RunUntilIdle(); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 395 | // Set an initial delay to ensure that the first call to TimeTicks::Now() |
| 396 | // before incrementing the counter does not return a null value. |
| 397 | FastForwardBy(TimeDelta::FromSeconds(1)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 398 | } |
| 399 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 400 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 401 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 402 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 403 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 404 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 405 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 406 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 407 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 408 | } |
| 409 | |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 410 | void Check100ResponseTiming(bool use_spdy); |
| 411 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 412 | // Either |write_failure| specifies a write failure or |read_failure| |
| 413 | // specifies a read failure when using a reused socket. In either case, the |
| 414 | // failure should cause the network transaction to resend the request, and the |
| 415 | // other argument should be NULL. |
| 416 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 417 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 418 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 419 | // Either |write_failure| specifies a write failure or |read_failure| |
| 420 | // specifies a read failure when using a reused socket. In either case, the |
| 421 | // failure should cause the network transaction to resend the request, and the |
| 422 | // other argument should be NULL. |
| 423 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 424 | const MockRead* read_failure, |
| 425 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 426 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 427 | SimpleGetHelperResult SimpleGetHelperForData( |
| 428 | base::span<StaticSocketDataProvider*> providers) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 429 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 430 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 431 | HttpRequestInfo request; |
| 432 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 433 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 434 | request.traffic_annotation = |
| 435 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 436 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 437 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 438 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 439 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 440 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 441 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 442 | for (auto* provider : providers) { |
| 443 | session_deps_.socket_factory->AddSocketDataProvider(provider); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 444 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 445 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 446 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 447 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 448 | EXPECT_TRUE(log.bound().IsCapturing()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 449 | int rv = trans.Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 450 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 451 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 452 | out.rv = callback.WaitForResult(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 453 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
| 454 | out.total_sent_bytes = trans.GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 455 | |
| 456 | // Even in the failure cases that use this function, connections are always |
| 457 | // successfully established before the error. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 458 | EXPECT_TRUE(trans.GetLoadTimingInfo(&out.load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 459 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 460 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 461 | if (out.rv != OK) |
| 462 | return out; |
| 463 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 464 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 465 | // Can't use ASSERT_* inside helper functions like this, so |
| 466 | // return an error. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 467 | if (!response || !response->headers) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 468 | out.rv = ERR_UNEXPECTED; |
| 469 | return out; |
| 470 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 471 | out.status_line = response->headers->GetStatusLine(); |
| 472 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 473 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 474 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 475 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 476 | bool got_endpoint = |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 477 | trans.GetRemoteEndpoint(&out.remote_endpoint_after_start); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 478 | EXPECT_EQ(got_endpoint, |
| 479 | out.remote_endpoint_after_start.address().size() > 0); |
| 480 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 481 | rv = ReadTransaction(&trans, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 482 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 483 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 484 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 485 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 486 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 487 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 488 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 489 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 490 | entries, pos, NetLogEventType::HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 491 | NetLogEventPhase::NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 492 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 493 | std::string line; |
| 494 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 495 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 496 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 497 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 498 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 499 | std::string value; |
| 500 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 501 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 502 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 503 | EXPECT_EQ("keep-alive", value); |
| 504 | |
| 505 | std::string response_headers; |
| 506 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 507 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 508 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 509 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 510 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 511 | // The total number of sent bytes should not have changed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 512 | EXPECT_EQ(out.total_sent_bytes, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 513 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 514 | trans.GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 515 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 516 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 517 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 518 | SimpleGetHelperResult SimpleGetHelper(base::span<const MockRead> data_reads) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 519 | MockWrite data_writes[] = { |
| 520 | MockWrite("GET / HTTP/1.1\r\n" |
| 521 | "Host: www.example.org\r\n" |
| 522 | "Connection: keep-alive\r\n\r\n"), |
| 523 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 524 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 525 | StaticSocketDataProvider reads(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 526 | StaticSocketDataProvider* data[] = {&reads}; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 527 | SimpleGetHelperResult out = SimpleGetHelperForData(data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 528 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 529 | EXPECT_EQ(CountWriteBytes(data_writes), out.total_sent_bytes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 530 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 531 | } |
| 532 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 533 | void AddSSLSocketData() { |
| 534 | ssl_.next_proto = kProtoHTTP2; |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 535 | ssl_.ssl_info.cert = |
| 536 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 537 | ASSERT_TRUE(ssl_.ssl_info.cert); |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 538 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_); |
| 539 | } |
| 540 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 541 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 542 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 543 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 544 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 545 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 546 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 547 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 548 | // These clocks are defined here, even though they're only used in the |
| 549 | // Reporting tests below, since they need to be destroyed after |
| 550 | // |session_deps_|. |
| 551 | base::SimpleTestClock clock_; |
| 552 | base::SimpleTestTickClock tick_clock_; |
| 553 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 554 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 555 | SpdySessionDependencies session_deps_; |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 556 | SSLSocketDataProvider ssl_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 557 | |
| 558 | // Original socket limits. Some tests set these. Safest to always restore |
| 559 | // them once each test has been run. |
| 560 | int old_max_group_sockets_; |
| 561 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 562 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 563 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 564 | namespace { |
| 565 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 566 | class BeforeHeadersSentHandler { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 567 | public: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 568 | BeforeHeadersSentHandler() |
| 569 | : observed_before_headers_sent_with_proxy_(false), |
| 570 | observed_before_headers_sent_(false) {} |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 571 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 572 | void OnBeforeHeadersSent(const ProxyInfo& proxy_info, |
| 573 | HttpRequestHeaders* request_headers) { |
| 574 | observed_before_headers_sent_ = true; |
| 575 | if (!proxy_info.is_http() && !proxy_info.is_https() && |
| 576 | !proxy_info.is_quic()) { |
| 577 | return; |
| 578 | } |
| 579 | observed_before_headers_sent_with_proxy_ = true; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 580 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 581 | } |
| 582 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 583 | bool observed_before_headers_sent_with_proxy() const { |
| 584 | return observed_before_headers_sent_with_proxy_; |
| 585 | } |
| 586 | |
| 587 | bool observed_before_headers_sent() const { |
| 588 | return observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | std::string observed_proxy_server_uri() const { |
| 592 | return observed_proxy_server_uri_; |
| 593 | } |
| 594 | |
| 595 | private: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 596 | bool observed_before_headers_sent_with_proxy_; |
| 597 | bool observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 598 | std::string observed_proxy_server_uri_; |
| 599 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 600 | DISALLOW_COPY_AND_ASSIGN(BeforeHeadersSentHandler); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 601 | }; |
| 602 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 603 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 604 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 605 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 606 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 607 | const int sizeof_row = strlen(row); |
| 608 | const int num_rows = static_cast<int>( |
| 609 | ceil(static_cast<float>(size) / sizeof_row)); |
| 610 | const int sizeof_data = num_rows * sizeof_row; |
| 611 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 612 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 613 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 614 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 615 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 616 | } |
| 617 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 618 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 619 | uint64_t MockGetMSTime() { |
| 620 | // Tue, 23 May 2017 20:13:07 +0000 |
| 621 | return 131400439870000000; |
| 622 | } |
| 623 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 624 | // Alternative functions that eliminate randomness and dependency on the local |
| 625 | // host name so that the generated NTLM messages are reproducible. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 626 | void MockGenerateRandom(uint8_t* output, size_t n) { |
| 627 | // This is set to 0xaa because the client challenge for testing in |
| 628 | // [MS-NLMP] Section 4.2.1 is 8 bytes of 0xaa. |
| 629 | memset(output, 0xaa, n); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 630 | } |
| 631 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 632 | std::string MockGetHostName() { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 633 | return ntlm::test::kHostnameAscii; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 634 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 635 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 636 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 637 | template<typename ParentPool> |
| 638 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 639 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 640 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 641 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 642 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 643 | const std::string last_group_name_received() const { |
| 644 | return last_group_name_; |
| 645 | } |
| 646 | |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 647 | bool socket_requested() const { return socket_requested_; } |
| 648 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 649 | int RequestSocket(const std::string& group_name, |
| 650 | const void* socket_params, |
| 651 | RequestPriority priority, |
Paul Jensen | 8d6f87ec | 2018-01-13 00:46:54 | [diff] [blame] | 652 | const SocketTag& socket_tag, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 653 | ClientSocketPool::RespectLimits respect_limits, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 654 | ClientSocketHandle* handle, |
Bence Béky | 5a8662b | 2018-07-03 13:04:03 | [diff] [blame] | 655 | CompletionOnceCallback callback, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 656 | const NetLogWithSource& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 657 | last_group_name_ = group_name; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 658 | socket_requested_ = true; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 659 | return ERR_IO_PENDING; |
| 660 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 661 | void CancelRequest(const std::string& group_name, |
| 662 | ClientSocketHandle* handle) override {} |
| 663 | void ReleaseSocket(const std::string& group_name, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 664 | std::unique_ptr<StreamSocket> socket, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 665 | int id) override {} |
| 666 | void CloseIdleSockets() override {} |
xunjieli | 92feb33 | 2017-03-03 17:19:23 | [diff] [blame] | 667 | void CloseIdleSocketsInGroup(const std::string& group_name) override {} |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 668 | int IdleSocketCount() const override { return 0; } |
| 669 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 670 | return 0; |
| 671 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 672 | LoadState GetLoadState(const std::string& group_name, |
| 673 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 674 | return LOAD_STATE_IDLE; |
| 675 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 676 | |
| 677 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 678 | std::string last_group_name_; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 679 | bool socket_requested_ = false; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 680 | }; |
| 681 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 682 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 683 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 684 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 685 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 686 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 687 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 688 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 689 | CaptureGroupNameSSLSocketPool; |
| 690 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 691 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 692 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 693 | HostResolver* host_resolver, |
| 694 | CertVerifier* /* cert_verifier */) |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 695 | : ParentPool(0, 0, host_resolver, NULL, NULL, NULL) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 696 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 697 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 698 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 699 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 700 | CertVerifier* /* cert_verifier */) |
Wojciech Dzierżanowski | 1f82356 | 2019-01-18 11:26:00 | [diff] [blame] | 701 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL, NULL, NULL) {} |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 702 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 703 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 704 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 705 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 706 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 707 | : SSLClientSocketPool(0, |
| 708 | 0, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 709 | cert_verifier, |
| 710 | NULL, |
| 711 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 712 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 713 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 714 | std::string(), |
| 715 | NULL, |
| 716 | NULL, |
| 717 | NULL, |
| 718 | NULL, |
| 719 | NULL, |
Matt Menke | c621aead0 | 2019-01-10 02:06:15 | [diff] [blame] | 720 | NULL, |
| 721 | NULL) {} |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 722 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 723 | //----------------------------------------------------------------------------- |
| 724 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 725 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 726 | // configured for common cases. |
| 727 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 728 | if (!auth_challenge) |
| 729 | return false; |
| 730 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 731 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 732 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 733 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 734 | return true; |
| 735 | } |
| 736 | |
| 737 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 738 | if (!auth_challenge) |
| 739 | return false; |
| 740 | EXPECT_TRUE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 741 | EXPECT_EQ("http://myproxy:70", auth_challenge->challenger.Serialize()); |
| 742 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 743 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 744 | return true; |
| 745 | } |
| 746 | |
| 747 | bool CheckBasicSecureProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 748 | if (!auth_challenge) |
| 749 | return false; |
| 750 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 751 | EXPECT_EQ("https://myproxy:70", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 752 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 753 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 754 | return true; |
| 755 | } |
| 756 | |
| 757 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 758 | if (!auth_challenge) |
| 759 | return false; |
| 760 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 761 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 762 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 763 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 764 | return true; |
| 765 | } |
| 766 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 767 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 768 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 769 | if (!auth_challenge) |
| 770 | return false; |
| 771 | EXPECT_FALSE(auth_challenge->is_proxy); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 772 | EXPECT_EQ("https://server", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 773 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 774 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 775 | return true; |
| 776 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 777 | |
| 778 | bool CheckNTLMProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 779 | if (!auth_challenge) |
| 780 | return false; |
| 781 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 782 | EXPECT_EQ("http://server", auth_challenge->challenger.Serialize()); |
| 783 | EXPECT_EQ(std::string(), auth_challenge->realm); |
| 784 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
| 785 | return true; |
| 786 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 787 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 788 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 789 | } // namespace |
| 790 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 791 | TEST_F(HttpNetworkTransactionTest, Basic) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 792 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 793 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 794 | } |
| 795 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 796 | TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 797 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 798 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 799 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 800 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 801 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 802 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 803 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 804 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 805 | EXPECT_EQ("hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 806 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 807 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 808 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 809 | |
| 810 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | // Response with no status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 814 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 815 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 816 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 817 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 818 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 819 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 820 | EXPECT_THAT(out.rv, IsOk()); |
| 821 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 822 | EXPECT_EQ("hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 823 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 824 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 825 | } |
| 826 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 827 | // Response with no status line, and a weird port. Should fail by default. |
| 828 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPort) { |
| 829 | MockRead data_reads[] = { |
| 830 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 831 | }; |
| 832 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 833 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 834 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 835 | |
| 836 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 837 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 838 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 839 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 840 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 841 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 842 | request.method = "GET"; |
| 843 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 844 | request.traffic_annotation = |
| 845 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 846 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 847 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 848 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 849 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 850 | } |
| 851 | |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 852 | // Tests that request info can be destroyed after the headers phase is complete. |
| 853 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoReadDestroyRequestInfo) { |
| 854 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 855 | auto trans = |
| 856 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 857 | |
| 858 | MockRead data_reads[] = { |
| 859 | MockRead("HTTP/1.0 200 OK\r\n"), MockRead("Connection: keep-alive\r\n"), |
| 860 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, 0), |
| 861 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 862 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 863 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 864 | |
| 865 | TestCompletionCallback callback; |
| 866 | |
| 867 | { |
| 868 | auto request = std::make_unique<HttpRequestInfo>(); |
| 869 | request->method = "GET"; |
| 870 | request->url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 871 | request->traffic_annotation = |
| 872 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 873 | |
| 874 | int rv = |
| 875 | trans->Start(request.get(), callback.callback(), NetLogWithSource()); |
| 876 | |
| 877 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 878 | } // Let request info be destroyed. |
| 879 | |
| 880 | trans.reset(); |
| 881 | } |
| 882 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 883 | // Response with no status line, and a weird port. Option to allow weird ports |
| 884 | // enabled. |
| 885 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPortAllowed) { |
| 886 | MockRead data_reads[] = { |
| 887 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 888 | }; |
| 889 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 890 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 891 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 892 | session_deps_.http_09_on_non_default_ports_enabled = true; |
| 893 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 894 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 895 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 896 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 897 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 898 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 899 | request.method = "GET"; |
| 900 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 901 | request.traffic_annotation = |
| 902 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 903 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 904 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 905 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 906 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 907 | |
| 908 | const HttpResponseInfo* info = trans->GetResponseInfo(); |
| 909 | ASSERT_TRUE(info->headers); |
| 910 | EXPECT_EQ("HTTP/0.9 200 OK", info->headers->GetStatusLine()); |
| 911 | |
| 912 | // Don't bother to read the body - that's verified elsewhere, important thing |
| 913 | // is that the option to allow HTTP/0.9 on non-default ports is respected. |
| 914 | } |
| 915 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 916 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 917 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 918 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 919 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 920 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 921 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 922 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 923 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 924 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 925 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 926 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 927 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 931 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 932 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 933 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 934 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 935 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 936 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 937 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 938 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 939 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 940 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 941 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | // Beyond 4 bytes of slop and it should fail to find a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 945 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 946 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 947 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 948 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 949 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 950 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 951 | EXPECT_THAT(out.rv, IsOk()); |
| 952 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 953 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 954 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 955 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 956 | } |
| 957 | |
| 958 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 959 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 960 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 961 | MockRead("\n"), |
| 962 | MockRead("\n"), |
| 963 | MockRead("Q"), |
| 964 | MockRead("J"), |
| 965 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 966 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 967 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 968 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 969 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 970 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 971 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 972 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 973 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | // Close the connection before enough bytes to have a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 977 | TEST_F(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 978 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 979 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 980 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 981 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 982 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 983 | EXPECT_THAT(out.rv, IsOk()); |
| 984 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 985 | EXPECT_EQ("HTT", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 986 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 987 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 988 | } |
| 989 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 990 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 991 | // persistent connection. The response should still terminate since a 204 |
| 992 | // cannot have a response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 993 | TEST_F(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 994 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 995 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 996 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 997 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 998 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 999 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1000 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1001 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1002 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 1003 | EXPECT_EQ("", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1004 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1005 | int64_t response_size = reads_size - strlen(junk); |
| 1006 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1007 | } |
| 1008 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1009 | // A simple request using chunked encoding with some extra data after. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1010 | TEST_F(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1011 | std::string final_chunk = "0\r\n\r\n"; |
| 1012 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 1013 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1014 | MockRead data_reads[] = { |
| 1015 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 1016 | MockRead("5\r\nHello\r\n"), |
| 1017 | MockRead("1\r\n"), |
| 1018 | MockRead(" \r\n"), |
| 1019 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1020 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1021 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1022 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1023 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1024 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1025 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1026 | EXPECT_EQ("Hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1027 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1028 | int64_t response_size = reads_size - extra_data.size(); |
| 1029 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1030 | } |
| 1031 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1032 | // Next tests deal with http://crbug.com/56344. |
| 1033 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1034 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1035 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 1036 | MockRead data_reads[] = { |
| 1037 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1038 | MockRead("Content-Length: 10\r\n"), |
| 1039 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1040 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1041 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1042 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1043 | } |
| 1044 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1045 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1046 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 1047 | MockRead data_reads[] = { |
| 1048 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1049 | MockRead("Content-Length: 5\r\n"), |
| 1050 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1051 | MockRead("Hello"), |
| 1052 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1053 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1054 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1055 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1056 | EXPECT_EQ("Hello", out.response_data); |
| 1057 | } |
| 1058 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1059 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1060 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 1061 | // More than 2 dupes. |
| 1062 | { |
| 1063 | MockRead data_reads[] = { |
| 1064 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1065 | MockRead("Content-Length: 5\r\n"), |
| 1066 | MockRead("Content-Length: 5\r\n"), |
| 1067 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1068 | MockRead("Hello"), |
| 1069 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1070 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1071 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1072 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1073 | EXPECT_EQ("Hello", out.response_data); |
| 1074 | } |
| 1075 | // HTTP/1.0 |
| 1076 | { |
| 1077 | MockRead data_reads[] = { |
| 1078 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1079 | MockRead("Content-Length: 5\r\n"), |
| 1080 | MockRead("Content-Length: 5\r\n"), |
| 1081 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1082 | MockRead("Hello"), |
| 1083 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1084 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1085 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1086 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 1087 | EXPECT_EQ("Hello", out.response_data); |
| 1088 | } |
| 1089 | // 2 dupes and one mismatched. |
| 1090 | { |
| 1091 | MockRead data_reads[] = { |
| 1092 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1093 | MockRead("Content-Length: 10\r\n"), |
| 1094 | MockRead("Content-Length: 10\r\n"), |
| 1095 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1096 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1097 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1098 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1099 | } |
| 1100 | } |
| 1101 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1102 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1103 | MultipleContentLengthHeadersTransferEncoding) { |
| 1104 | MockRead data_reads[] = { |
| 1105 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1106 | MockRead("Content-Length: 666\r\n"), |
| 1107 | MockRead("Content-Length: 1337\r\n"), |
| 1108 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 1109 | MockRead("5\r\nHello\r\n"), |
| 1110 | MockRead("1\r\n"), |
| 1111 | MockRead(" \r\n"), |
| 1112 | MockRead("5\r\nworld\r\n"), |
| 1113 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1114 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1115 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1116 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1117 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1118 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1119 | EXPECT_EQ("Hello world", out.response_data); |
| 1120 | } |
| 1121 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1122 | // Next tests deal with http://crbug.com/98895. |
| 1123 | |
| 1124 | // Checks that a single Content-Disposition header results in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1125 | TEST_F(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1126 | MockRead data_reads[] = { |
| 1127 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1128 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 1129 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1130 | MockRead("Hello"), |
| 1131 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1132 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1133 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1134 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1135 | EXPECT_EQ("Hello", out.response_data); |
| 1136 | } |
| 1137 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1138 | // Checks that two identical Content-Disposition headers result in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1139 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1140 | MockRead data_reads[] = { |
| 1141 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1142 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1143 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1144 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1145 | MockRead("Hello"), |
| 1146 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1147 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1148 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1149 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1150 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1151 | } |
| 1152 | |
| 1153 | // Checks that two distinct Content-Disposition headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1154 | TEST_F(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1155 | MockRead data_reads[] = { |
| 1156 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1157 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1158 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1159 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1160 | MockRead("Hello"), |
| 1161 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1162 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1163 | EXPECT_THAT(out.rv, |
| 1164 | IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1165 | } |
| 1166 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1167 | // Checks that two identical Location headers result in no error. |
| 1168 | // Also tests Location header behavior. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1169 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1170 | MockRead data_reads[] = { |
| 1171 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1172 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1173 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1174 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1175 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1176 | }; |
| 1177 | |
| 1178 | HttpRequestInfo request; |
| 1179 | request.method = "GET"; |
| 1180 | request.url = GURL("http://redirect.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1181 | request.traffic_annotation = |
| 1182 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1183 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1184 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1185 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1186 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1187 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1188 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1189 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1190 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1191 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1192 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1193 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1194 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1195 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1196 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1197 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1198 | ASSERT_TRUE(response); |
| 1199 | ASSERT_TRUE(response->headers); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1200 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1201 | std::string url; |
| 1202 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1203 | EXPECT_EQ("http://good.com/", url); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1204 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1205 | } |
| 1206 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1207 | // Checks that two distinct Location headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1208 | TEST_F(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1209 | MockRead data_reads[] = { |
| 1210 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1211 | MockRead("Location: http://good.com/\r\n"), |
| 1212 | MockRead("Location: http://evil.com/\r\n"), |
| 1213 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1214 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1215 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1216 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1217 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1218 | } |
| 1219 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1220 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1221 | // message body (since HEAD has none). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1222 | TEST_F(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1223 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1224 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1225 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1226 | request.traffic_annotation = |
| 1227 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1228 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1229 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1230 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1231 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1232 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1233 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 1234 | base::Unretained(&headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1235 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1236 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1237 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1238 | "Host: www.example.org\r\n" |
| 1239 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1240 | }; |
| 1241 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1242 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1243 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1244 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1245 | // No response body because the test stops reading here. |
| 1246 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1247 | }; |
| 1248 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1249 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1250 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1251 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1252 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1253 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1254 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1255 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1256 | |
| 1257 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1258 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1259 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1260 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1261 | ASSERT_TRUE(response); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1262 | |
| 1263 | // Check that the headers got parsed. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1264 | EXPECT_TRUE(response->headers); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1265 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1266 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1267 | EXPECT_TRUE(response->proxy_server.is_direct()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1268 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 1269 | EXPECT_FALSE(headers_handler.observed_before_headers_sent_with_proxy()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1270 | |
| 1271 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1272 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1273 | bool has_server_header = response->headers->EnumerateHeader( |
| 1274 | &iter, "Server", &server_header); |
| 1275 | EXPECT_TRUE(has_server_header); |
| 1276 | EXPECT_EQ("Blah", server_header); |
| 1277 | |
| 1278 | // Reading should give EOF right away, since there is no message body |
| 1279 | // (despite non-zero content-length). |
| 1280 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1281 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1282 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1283 | EXPECT_EQ("", response_data); |
| 1284 | } |
| 1285 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1286 | TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1287 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1288 | |
| 1289 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1290 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1291 | MockRead("hello"), |
| 1292 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1293 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1294 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1295 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1296 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1297 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1298 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1299 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1300 | "hello", "world" |
| 1301 | }; |
| 1302 | |
| 1303 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1304 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1305 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1306 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1307 | request.traffic_annotation = |
| 1308 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1309 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1310 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1311 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1312 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1313 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1314 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1315 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1316 | |
| 1317 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1318 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1319 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1320 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1321 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1322 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1323 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1324 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1325 | EXPECT_TRUE(response->proxy_server.is_direct()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1326 | |
| 1327 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1328 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1329 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1330 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1331 | } |
| 1332 | } |
| 1333 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1334 | TEST_F(HttpNetworkTransactionTest, Ignores100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1335 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1336 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1337 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1338 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1339 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1340 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1341 | request.method = "POST"; |
| 1342 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1343 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1344 | request.traffic_annotation = |
| 1345 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1346 | |
shivanisha | b9a14395 | 2016-09-19 17:23:41 | [diff] [blame] | 1347 | // Check the upload progress returned before initialization is correct. |
| 1348 | UploadProgress progress = request.upload_data_stream->GetUploadProgress(); |
| 1349 | EXPECT_EQ(0u, progress.size()); |
| 1350 | EXPECT_EQ(0u, progress.position()); |
| 1351 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1352 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1353 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1354 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1355 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1356 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1357 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1358 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1359 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1360 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1361 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1362 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1363 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1364 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1365 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1366 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1367 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1368 | |
| 1369 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1370 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1371 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1372 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1373 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1374 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1375 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1376 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1377 | |
| 1378 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1379 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1380 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1381 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1382 | } |
| 1383 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1384 | // This test is almost the same as Ignores100 above, but the response contains |
| 1385 | // 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] | 1386 | // HTTP/1.1 and the two status headers are read in one read. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1387 | TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1388 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1389 | request.method = "GET"; |
| 1390 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1391 | request.traffic_annotation = |
| 1392 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1393 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1394 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1395 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1396 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1397 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1398 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1399 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1400 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1401 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1402 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1403 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1404 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1405 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1406 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1407 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1408 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1409 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1410 | |
| 1411 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1412 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1413 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1414 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1415 | ASSERT_TRUE(response); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1416 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1417 | EXPECT_TRUE(response->headers); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1418 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1419 | |
| 1420 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1421 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1422 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1423 | EXPECT_EQ("hello world", response_data); |
| 1424 | } |
| 1425 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1426 | TEST_F(HttpNetworkTransactionTest, LoadTimingMeasuresTimeToFirstByteForHttp) { |
| 1427 | static const base::TimeDelta kDelayAfterFirstByte = |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1428 | base::TimeDelta::FromMilliseconds(10); |
| 1429 | |
| 1430 | HttpRequestInfo request; |
| 1431 | request.method = "GET"; |
| 1432 | request.url = GURL("http://www.foo.com/"); |
| 1433 | request.traffic_annotation = |
| 1434 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1435 | |
| 1436 | std::vector<MockWrite> data_writes = { |
| 1437 | MockWrite(ASYNC, 0, |
| 1438 | "GET / HTTP/1.1\r\n" |
| 1439 | "Host: www.foo.com\r\n" |
| 1440 | "Connection: keep-alive\r\n\r\n"), |
| 1441 | }; |
| 1442 | |
| 1443 | std::vector<MockRead> data_reads = { |
| 1444 | // Write one byte of the status line, followed by a pause. |
| 1445 | MockRead(ASYNC, 1, "H"), |
| 1446 | MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1447 | MockRead(ASYNC, 3, "TTP/1.1 200 OK\r\n\r\n"), |
| 1448 | MockRead(ASYNC, 4, "hello world"), |
| 1449 | MockRead(SYNCHRONOUS, OK, 5), |
| 1450 | }; |
| 1451 | |
| 1452 | SequencedSocketData data(data_reads, data_writes); |
| 1453 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1454 | |
| 1455 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1456 | |
| 1457 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1458 | |
| 1459 | TestCompletionCallback callback; |
| 1460 | |
| 1461 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1462 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1463 | |
| 1464 | data.RunUntilPaused(); |
| 1465 | ASSERT_TRUE(data.IsPaused()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1466 | FastForwardBy(kDelayAfterFirstByte); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1467 | data.Resume(); |
| 1468 | |
| 1469 | rv = callback.WaitForResult(); |
| 1470 | EXPECT_THAT(rv, IsOk()); |
| 1471 | |
| 1472 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 1473 | ASSERT_TRUE(response); |
| 1474 | |
| 1475 | EXPECT_TRUE(response->headers); |
| 1476 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1477 | |
| 1478 | LoadTimingInfo load_timing_info; |
| 1479 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 1480 | EXPECT_FALSE(load_timing_info.receive_headers_start.is_null()); |
| 1481 | EXPECT_FALSE(load_timing_info.connect_timing.connect_end.is_null()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1482 | // Ensure we didn't include the delay in the TTFB time. |
| 1483 | EXPECT_EQ(load_timing_info.receive_headers_start, |
| 1484 | load_timing_info.connect_timing.connect_end); |
| 1485 | // Ensure that the mock clock advanced at all. |
| 1486 | EXPECT_EQ(base::TimeTicks::Now() - load_timing_info.receive_headers_start, |
| 1487 | kDelayAfterFirstByte); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1488 | |
| 1489 | std::string response_data; |
| 1490 | rv = ReadTransaction(&trans, &response_data); |
| 1491 | EXPECT_THAT(rv, IsOk()); |
| 1492 | EXPECT_EQ("hello world", response_data); |
| 1493 | } |
| 1494 | |
| 1495 | // Tests that the time-to-first-byte reported in a transaction's load timing |
| 1496 | // info uses the first response, even if 1XX/informational. |
| 1497 | void HttpNetworkTransactionTest::Check100ResponseTiming(bool use_spdy) { |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1498 | static const base::TimeDelta kDelayAfter100Response = |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1499 | base::TimeDelta::FromMilliseconds(10); |
| 1500 | |
| 1501 | HttpRequestInfo request; |
| 1502 | request.method = "GET"; |
| 1503 | request.url = GURL("https://www.foo.com/"); |
| 1504 | request.traffic_annotation = |
| 1505 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1506 | |
| 1507 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 1508 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 1509 | |
| 1510 | std::vector<MockWrite> data_writes; |
| 1511 | std::vector<MockRead> data_reads; |
| 1512 | |
| 1513 | spdy::SpdySerializedFrame spdy_req( |
| 1514 | spdy_util_.ConstructSpdyGet(request.url.spec().c_str(), 1, LOWEST)); |
| 1515 | |
| 1516 | spdy::SpdyHeaderBlock spdy_resp1_headers; |
| 1517 | spdy_resp1_headers[spdy::kHttp2StatusHeader] = "100"; |
| 1518 | spdy::SpdySerializedFrame spdy_resp1( |
| 1519 | spdy_util_.ConstructSpdyReply(1, spdy_resp1_headers.Clone())); |
| 1520 | spdy::SpdySerializedFrame spdy_resp2( |
| 1521 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 1522 | spdy::SpdySerializedFrame spdy_data( |
| 1523 | spdy_util_.ConstructSpdyDataFrame(1, "hello world", true)); |
| 1524 | |
| 1525 | if (use_spdy) { |
| 1526 | ssl.next_proto = kProtoHTTP2; |
| 1527 | |
| 1528 | data_writes = {CreateMockWrite(spdy_req, 0)}; |
| 1529 | |
| 1530 | data_reads = { |
| 1531 | CreateMockRead(spdy_resp1, 1), MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1532 | CreateMockRead(spdy_resp2, 3), CreateMockRead(spdy_data, 4), |
| 1533 | MockRead(SYNCHRONOUS, OK, 5), |
| 1534 | }; |
| 1535 | } else { |
| 1536 | data_writes = { |
| 1537 | MockWrite(ASYNC, 0, |
| 1538 | "GET / HTTP/1.1\r\n" |
| 1539 | "Host: www.foo.com\r\n" |
| 1540 | "Connection: keep-alive\r\n\r\n"), |
| 1541 | }; |
| 1542 | |
| 1543 | data_reads = { |
| 1544 | MockRead(ASYNC, 1, "HTTP/1.1 100 Continue\r\n\r\n"), |
| 1545 | MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1546 | |
| 1547 | MockRead(ASYNC, 3, "HTTP/1.1 200 OK\r\n\r\n"), |
| 1548 | MockRead(ASYNC, 4, "hello world"), |
| 1549 | MockRead(SYNCHRONOUS, OK, 5), |
| 1550 | }; |
| 1551 | } |
| 1552 | |
| 1553 | SequencedSocketData data(data_reads, data_writes); |
| 1554 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1555 | |
| 1556 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1557 | |
| 1558 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1559 | |
| 1560 | TestCompletionCallback callback; |
| 1561 | |
| 1562 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1563 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1564 | |
| 1565 | data.RunUntilPaused(); |
| 1566 | // We should now have parsed the 100 response and hit ERR_IO_PENDING. Insert |
| 1567 | // the delay before parsing the 200 response. |
| 1568 | ASSERT_TRUE(data.IsPaused()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1569 | FastForwardBy(kDelayAfter100Response); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1570 | data.Resume(); |
| 1571 | |
| 1572 | rv = callback.WaitForResult(); |
| 1573 | EXPECT_THAT(rv, IsOk()); |
| 1574 | |
| 1575 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 1576 | ASSERT_TRUE(response); |
| 1577 | |
| 1578 | LoadTimingInfo load_timing_info; |
| 1579 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 1580 | EXPECT_FALSE(load_timing_info.receive_headers_start.is_null()); |
| 1581 | EXPECT_FALSE(load_timing_info.connect_timing.connect_end.is_null()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1582 | // Ensure we didn't include the delay in the TTFB time. |
| 1583 | EXPECT_EQ(load_timing_info.receive_headers_start, |
| 1584 | load_timing_info.connect_timing.connect_end); |
| 1585 | // Ensure that the mock clock advanced at all. |
| 1586 | EXPECT_EQ(base::TimeTicks::Now() - load_timing_info.receive_headers_start, |
| 1587 | kDelayAfter100Response); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1588 | |
| 1589 | std::string response_data; |
| 1590 | rv = ReadTransaction(&trans, &response_data); |
| 1591 | EXPECT_THAT(rv, IsOk()); |
| 1592 | EXPECT_EQ("hello world", response_data); |
| 1593 | } |
| 1594 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1595 | TEST_F(HttpNetworkTransactionTest, MeasuresTimeToFirst100ResponseForHttp) { |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1596 | Check100ResponseTiming(false /* use_spdy */); |
| 1597 | } |
| 1598 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1599 | TEST_F(HttpNetworkTransactionTest, MeasuresTimeToFirst100ResponseForSpdy) { |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1600 | Check100ResponseTiming(true /* use_spdy */); |
| 1601 | } |
| 1602 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1603 | TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1604 | HttpRequestInfo request; |
| 1605 | request.method = "POST"; |
| 1606 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1607 | request.traffic_annotation = |
| 1608 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1609 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1610 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1611 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1612 | |
| 1613 | MockRead data_reads[] = { |
| 1614 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1615 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1616 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1617 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1618 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1619 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1620 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1621 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1622 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1623 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1624 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1625 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1626 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1627 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1628 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1629 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1630 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1631 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1632 | } |
| 1633 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1634 | TEST_F(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1635 | HttpRequestInfo request; |
| 1636 | request.method = "POST"; |
| 1637 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1638 | request.traffic_annotation = |
| 1639 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1640 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1641 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1642 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1643 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1644 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1645 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1646 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1647 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1648 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1649 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1650 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1651 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1652 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1653 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1654 | |
| 1655 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1656 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1657 | } |
| 1658 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1659 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1660 | const MockWrite* write_failure, |
| 1661 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1662 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1663 | request.method = "GET"; |
| 1664 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1665 | request.traffic_annotation = |
| 1666 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1667 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1668 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1669 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1670 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1671 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1672 | // Written data for successfully sending both requests. |
| 1673 | MockWrite data1_writes[] = { |
| 1674 | MockWrite("GET / HTTP/1.1\r\n" |
| 1675 | "Host: www.foo.com\r\n" |
| 1676 | "Connection: keep-alive\r\n\r\n"), |
| 1677 | MockWrite("GET / HTTP/1.1\r\n" |
| 1678 | "Host: www.foo.com\r\n" |
| 1679 | "Connection: keep-alive\r\n\r\n") |
| 1680 | }; |
| 1681 | |
| 1682 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1683 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1684 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1685 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1686 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1687 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1688 | |
| 1689 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1690 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1691 | data1_writes[1] = *write_failure; |
| 1692 | } else { |
| 1693 | ASSERT_TRUE(read_failure); |
| 1694 | data1_reads[2] = *read_failure; |
| 1695 | } |
| 1696 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1697 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1698 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1699 | |
| 1700 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1701 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1702 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1703 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1704 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1705 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1706 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1707 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1708 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1709 | "hello", "world" |
| 1710 | }; |
| 1711 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1712 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1713 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1714 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1715 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1716 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1717 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1718 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1719 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1720 | |
| 1721 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1722 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1723 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1724 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1725 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1726 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1727 | if (i == 0) { |
| 1728 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1729 | } else { |
| 1730 | // The second request should be using a new socket. |
| 1731 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1732 | } |
| 1733 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1734 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1735 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1736 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1737 | EXPECT_TRUE(response->headers); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1738 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1739 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1740 | |
| 1741 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1742 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1743 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1744 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1745 | } |
| 1746 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1747 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1748 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1749 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1750 | const MockRead* read_failure, |
| 1751 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1752 | HttpRequestInfo request; |
| 1753 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1754 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1755 | request.traffic_annotation = |
| 1756 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1757 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1758 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1759 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1760 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1761 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1762 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1763 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1764 | if (use_spdy) { |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 1765 | ssl1.next_proto = kProtoHTTP2; |
| 1766 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1767 | } |
| 1768 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1769 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1770 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1771 | // SPDY versions of the request and response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1772 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1773 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1774 | spdy::SpdySerializedFrame spdy_response( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1775 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1776 | spdy::SpdySerializedFrame spdy_data( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 1777 | spdy_util_.ConstructSpdyDataFrame(1, "hello", true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1778 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1779 | // HTTP/1.1 versions of the request and response. |
| 1780 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1781 | "Host: www.foo.com\r\n" |
| 1782 | "Connection: keep-alive\r\n\r\n"; |
| 1783 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1784 | const char kHttpData[] = "hello"; |
| 1785 | |
| 1786 | std::vector<MockRead> data1_reads; |
| 1787 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1788 | if (write_failure) { |
| 1789 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1790 | data1_writes.push_back(*write_failure); |
| 1791 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1792 | } else { |
| 1793 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1794 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1795 | data1_writes.push_back(CreateMockWrite(spdy_request)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1796 | } else { |
| 1797 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1798 | } |
| 1799 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1800 | } |
| 1801 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1802 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1803 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1804 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1805 | std::vector<MockRead> data2_reads; |
| 1806 | std::vector<MockWrite> data2_writes; |
| 1807 | |
| 1808 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1809 | data2_writes.push_back(CreateMockWrite(spdy_request, 0, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1810 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1811 | data2_reads.push_back(CreateMockRead(spdy_response, 1, ASYNC)); |
| 1812 | data2_reads.push_back(CreateMockRead(spdy_data, 2, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1813 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1814 | } else { |
| 1815 | data2_writes.push_back( |
| 1816 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1817 | |
| 1818 | data2_reads.push_back( |
| 1819 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1820 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1821 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1822 | } |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1823 | SequencedSocketData data2(data2_reads, data2_writes); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1824 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1825 | |
| 1826 | // Preconnect a socket. |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 1827 | session->http_stream_factory()->PreconnectStreams(1, request); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1828 | // Wait for the preconnect to complete. |
| 1829 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1830 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1831 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1832 | |
| 1833 | // Make the request. |
| 1834 | TestCompletionCallback callback; |
| 1835 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1836 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1837 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1838 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1839 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1840 | |
| 1841 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1842 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1843 | |
| 1844 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1845 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1846 | TestLoadTimingNotReused( |
| 1847 | load_timing_info, |
| 1848 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1849 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1850 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1851 | ASSERT_TRUE(response); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1852 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1853 | EXPECT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1854 | if (response->was_fetched_via_spdy) { |
| 1855 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1856 | } else { |
| 1857 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1858 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1859 | |
| 1860 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1861 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1862 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1863 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1864 | } |
| 1865 | |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1866 | // Test that we do not retry indefinitely when a server sends an error like |
| 1867 | // ERR_SPDY_PING_FAILED, ERR_SPDY_SERVER_REFUSED_STREAM, |
| 1868 | // ERR_QUIC_HANDSHAKE_FAILED or ERR_QUIC_PROTOCOL_ERROR. |
| 1869 | TEST_F(HttpNetworkTransactionTest, FiniteRetriesOnIOError) { |
| 1870 | HttpRequestInfo request; |
| 1871 | request.method = "GET"; |
| 1872 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1873 | request.traffic_annotation = |
| 1874 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1875 | |
| 1876 | // Check whether we give up after the third try. |
| 1877 | |
| 1878 | // Construct an HTTP2 request and a "Go away" response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1879 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1880 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1881 | spdy::SpdySerializedFrame spdy_response_go_away( |
| 1882 | spdy_util_.ConstructSpdyGoAway(0)); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1883 | MockRead data_read1[] = {CreateMockRead(spdy_response_go_away)}; |
| 1884 | MockWrite data_write[] = {CreateMockWrite(spdy_request, 0)}; |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1885 | |
| 1886 | // Three go away responses. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1887 | StaticSocketDataProvider data1(data_read1, data_write); |
| 1888 | StaticSocketDataProvider data2(data_read1, data_write); |
| 1889 | StaticSocketDataProvider data3(data_read1, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1890 | |
| 1891 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1892 | AddSSLSocketData(); |
| 1893 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1894 | AddSSLSocketData(); |
| 1895 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1896 | AddSSLSocketData(); |
| 1897 | |
| 1898 | TestCompletionCallback callback; |
| 1899 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1900 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1901 | |
| 1902 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1903 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1904 | |
| 1905 | rv = callback.WaitForResult(); |
| 1906 | EXPECT_THAT(rv, IsError(ERR_SPDY_SERVER_REFUSED_STREAM)); |
| 1907 | } |
| 1908 | |
| 1909 | TEST_F(HttpNetworkTransactionTest, RetryTwiceOnIOError) { |
| 1910 | HttpRequestInfo request; |
| 1911 | request.method = "GET"; |
| 1912 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1913 | request.traffic_annotation = |
| 1914 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1915 | |
| 1916 | // Check whether we try atleast thrice before giving up. |
| 1917 | |
| 1918 | // Construct an HTTP2 request and a "Go away" response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1919 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1920 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1921 | spdy::SpdySerializedFrame spdy_response_go_away( |
| 1922 | spdy_util_.ConstructSpdyGoAway(0)); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1923 | MockRead data_read1[] = {CreateMockRead(spdy_response_go_away)}; |
| 1924 | MockWrite data_write[] = {CreateMockWrite(spdy_request, 0)}; |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1925 | |
| 1926 | // Construct a non error HTTP2 response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1927 | spdy::SpdySerializedFrame spdy_response_no_error( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1928 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1929 | spdy::SpdySerializedFrame spdy_data( |
| 1930 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1931 | MockRead data_read2[] = {CreateMockRead(spdy_response_no_error, 1), |
| 1932 | CreateMockRead(spdy_data, 2)}; |
| 1933 | |
| 1934 | // Two error responses. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1935 | StaticSocketDataProvider data1(data_read1, data_write); |
| 1936 | StaticSocketDataProvider data2(data_read1, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1937 | // Followed by a success response. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1938 | SequencedSocketData data3(data_read2, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1939 | |
| 1940 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1941 | AddSSLSocketData(); |
| 1942 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1943 | AddSSLSocketData(); |
| 1944 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1945 | AddSSLSocketData(); |
| 1946 | |
| 1947 | TestCompletionCallback callback; |
| 1948 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1949 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1950 | |
| 1951 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1952 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1953 | |
| 1954 | rv = callback.WaitForResult(); |
| 1955 | EXPECT_THAT(rv, IsOk()); |
| 1956 | } |
| 1957 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1958 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1959 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1960 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1961 | } |
| 1962 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1963 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1964 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1965 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1966 | } |
| 1967 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1968 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1969 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1970 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1971 | } |
| 1972 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1973 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1974 | // if the socket was a reused keep alive socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1975 | TEST_F(HttpNetworkTransactionTest, KeepAlive408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1976 | MockRead read_failure(SYNCHRONOUS, |
| 1977 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1978 | "Connection: Keep-Alive\r\n" |
| 1979 | "Content-Length: 6\r\n\r\n" |
| 1980 | "Pickle"); |
| 1981 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1982 | } |
| 1983 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1984 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorNotConnectedOnWrite) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1985 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1986 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1987 | } |
| 1988 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1989 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorReset) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1990 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1991 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1992 | } |
| 1993 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1994 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1995 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1996 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1997 | } |
| 1998 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1999 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2000 | MockRead read_failure(ASYNC, OK); // EOF |
| 2001 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 2002 | } |
| 2003 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 2004 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 2005 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2006 | TEST_F(HttpNetworkTransactionTest, RetryOnIdle408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 2007 | MockRead read_failure(SYNCHRONOUS, |
| 2008 | "HTTP/1.1 408 Request Timeout\r\n" |
| 2009 | "Connection: Keep-Alive\r\n" |
| 2010 | "Content-Length: 6\r\n\r\n" |
| 2011 | "Pickle"); |
| 2012 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 2013 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 2014 | } |
| 2015 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2016 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorNotConnectedOnWrite) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2017 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 2018 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 2019 | } |
| 2020 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2021 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2022 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 2023 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 2024 | } |
| 2025 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2026 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2027 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 2028 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 2029 | } |
| 2030 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2031 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2032 | MockRead read_failure(ASYNC, OK); // EOF |
| 2033 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2034 | } |
| 2035 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2036 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2037 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2038 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2039 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2040 | request.traffic_annotation = |
| 2041 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2042 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2043 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2044 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2045 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2046 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2047 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 2048 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 2049 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2050 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2051 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2052 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2053 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2054 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2055 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2056 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2057 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2058 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2059 | |
| 2060 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2061 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2062 | |
| 2063 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2064 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2065 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2066 | } |
| 2067 | |
| 2068 | // What do various browsers do when the server closes a non-keepalive |
| 2069 | // connection without sending any response header or body? |
| 2070 | // |
| 2071 | // IE7: error page |
| 2072 | // Safari 3.1.2 (Windows): error page |
| 2073 | // Firefox 3.0.1: blank page |
| 2074 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2075 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 2076 | // Us: error page (EMPTY_RESPONSE) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2077 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2078 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2079 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 2080 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 2081 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2082 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2083 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2084 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2085 | EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2086 | } |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 2087 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2088 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 2089 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 2090 | // destructor in such situations. |
| 2091 | // See http://crbug.com/154712 and http://crbug.com/156609. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2092 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2093 | HttpRequestInfo request; |
| 2094 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2095 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2096 | request.traffic_annotation = |
| 2097 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2098 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2099 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2100 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2101 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2102 | |
| 2103 | MockRead data_reads[] = { |
| 2104 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2105 | MockRead("Connection: keep-alive\r\n"), |
| 2106 | MockRead("Content-Length: 100\r\n\r\n"), |
| 2107 | MockRead("hello"), |
| 2108 | MockRead(SYNCHRONOUS, 0), |
| 2109 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2110 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2111 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2112 | |
| 2113 | TestCompletionCallback callback; |
| 2114 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2115 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2116 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2117 | |
| 2118 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2119 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2120 | |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 2121 | scoped_refptr<IOBufferWithSize> io_buf = |
| 2122 | base::MakeRefCounted<IOBufferWithSize>(100); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2123 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2124 | if (rv == ERR_IO_PENDING) |
| 2125 | rv = callback.WaitForResult(); |
| 2126 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2127 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2128 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2129 | |
| 2130 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 2131 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2132 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2133 | } |
| 2134 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2135 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2136 | HttpRequestInfo request; |
| 2137 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2138 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2139 | request.traffic_annotation = |
| 2140 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2141 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2142 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2143 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2144 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2145 | |
| 2146 | MockRead data_reads[] = { |
| 2147 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2148 | MockRead("Connection: keep-alive\r\n"), |
| 2149 | MockRead("Content-Length: 100\r\n\r\n"), |
| 2150 | MockRead(SYNCHRONOUS, 0), |
| 2151 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2152 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2153 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2154 | |
| 2155 | TestCompletionCallback callback; |
| 2156 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2157 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2158 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2159 | |
| 2160 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2161 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2162 | |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 2163 | scoped_refptr<IOBufferWithSize> io_buf( |
| 2164 | base::MakeRefCounted<IOBufferWithSize>(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2165 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2166 | if (rv == ERR_IO_PENDING) |
| 2167 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2168 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2169 | |
| 2170 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 2171 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2172 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2173 | } |
| 2174 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2175 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 2176 | // reading the body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2177 | TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2178 | HttpRequestInfo request; |
| 2179 | request.method = "GET"; |
| 2180 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2181 | request.traffic_annotation = |
| 2182 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2183 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2184 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2185 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2186 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2187 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2188 | const char* request_data = |
| 2189 | "GET / HTTP/1.1\r\n" |
| 2190 | "Host: www.foo.com\r\n" |
| 2191 | "Connection: keep-alive\r\n\r\n"; |
| 2192 | MockWrite data_writes[] = { |
| 2193 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 2194 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 2195 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 2196 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 2197 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 2198 | }; |
| 2199 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2200 | // Note that because all these reads happen in the same |
| 2201 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 2202 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2203 | MockRead data_reads[] = { |
| 2204 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 2205 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 2206 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 2207 | MockRead(ASYNC, 7, |
| 2208 | "HTTP/1.1 302 Found\r\n" |
| 2209 | "Content-Length: 0\r\n\r\n"), |
| 2210 | MockRead(ASYNC, 9, |
| 2211 | "HTTP/1.1 302 Found\r\n" |
| 2212 | "Content-Length: 5\r\n\r\n" |
| 2213 | "hello"), |
| 2214 | MockRead(ASYNC, 11, |
| 2215 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2216 | "Content-Length: 0\r\n\r\n"), |
| 2217 | MockRead(ASYNC, 13, |
| 2218 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2219 | "Content-Length: 5\r\n\r\n" |
| 2220 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2221 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2222 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 2223 | // the set_busy_before_sync_reads(true) call, while the |
| 2224 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 2225 | // reuseable. See http://crbug.com/544255. |
| 2226 | MockRead(ASYNC, 15, |
| 2227 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2228 | "Content-Length: 5\r\n\r\n"), |
| 2229 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2230 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2231 | MockRead(ASYNC, 18, |
| 2232 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2233 | "Content-Length: 5\r\n\r\n" |
| 2234 | "he"), |
| 2235 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 2236 | |
| 2237 | // The body of the final request is actually read. |
| 2238 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 2239 | MockRead(ASYNC, 22, "hello"), |
| 2240 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2241 | SequencedSocketData data(data_reads, data_writes); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2242 | data.set_busy_before_sync_reads(true); |
| 2243 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2244 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 2245 | const int kNumUnreadBodies = base::size(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2246 | std::string response_lines[kNumUnreadBodies]; |
| 2247 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 2248 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2249 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2250 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2251 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2252 | auto trans = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2253 | session.get()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2254 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2255 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2256 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2257 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2258 | LoadTimingInfo load_timing_info; |
| 2259 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2260 | if (i == 0) { |
| 2261 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2262 | first_socket_log_id = load_timing_info.socket_log_id; |
| 2263 | } else { |
| 2264 | TestLoadTimingReused(load_timing_info); |
| 2265 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 2266 | } |
| 2267 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2268 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2269 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2270 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2271 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2272 | response_lines[i] = response->headers->GetStatusLine(); |
| 2273 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2274 | // Delete the transaction without reading the response bodies. Then spin |
| 2275 | // the message loop, so the response bodies are drained. |
| 2276 | trans.reset(); |
| 2277 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2278 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2279 | |
| 2280 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2281 | "HTTP/1.1 204 No Content", |
| 2282 | "HTTP/1.1 205 Reset Content", |
| 2283 | "HTTP/1.1 304 Not Modified", |
| 2284 | "HTTP/1.1 302 Found", |
| 2285 | "HTTP/1.1 302 Found", |
| 2286 | "HTTP/1.1 301 Moved Permanently", |
| 2287 | "HTTP/1.1 301 Moved Permanently", |
| 2288 | "HTTP/1.1 200 Hunky-Dory", |
| 2289 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2290 | }; |
| 2291 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 2292 | static_assert(kNumUnreadBodies == base::size(kStatusLines), |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 2293 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2294 | |
| 2295 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 2296 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 2297 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2298 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2299 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2300 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2301 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2302 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2303 | ASSERT_TRUE(response); |
| 2304 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2305 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2306 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2307 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2308 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2309 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2310 | } |
| 2311 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2312 | // Sockets that receive extra data after a response is complete should not be |
| 2313 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2314 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2315 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2316 | MockWrite data_writes1[] = { |
| 2317 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 2318 | "Host: www.borked.com\r\n" |
| 2319 | "Connection: keep-alive\r\n\r\n"), |
| 2320 | }; |
| 2321 | |
| 2322 | MockRead data_reads1[] = { |
| 2323 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2324 | "Connection: keep-alive\r\n" |
| 2325 | "Content-Length: 22\r\n\r\n" |
| 2326 | "This server is borked."), |
| 2327 | }; |
| 2328 | |
| 2329 | MockWrite data_writes2[] = { |
| 2330 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2331 | "Host: www.borked.com\r\n" |
| 2332 | "Connection: keep-alive\r\n\r\n"), |
| 2333 | }; |
| 2334 | |
| 2335 | MockRead data_reads2[] = { |
| 2336 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2337 | "Content-Length: 3\r\n\r\n" |
| 2338 | "foo"), |
| 2339 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2340 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2341 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2342 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2343 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2344 | |
| 2345 | TestCompletionCallback callback; |
| 2346 | HttpRequestInfo request1; |
| 2347 | request1.method = "HEAD"; |
| 2348 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2349 | request1.traffic_annotation = |
| 2350 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2351 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2352 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2353 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2354 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2355 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2356 | |
| 2357 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2358 | ASSERT_TRUE(response1); |
| 2359 | ASSERT_TRUE(response1->headers); |
| 2360 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2361 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2362 | |
| 2363 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2364 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2365 | EXPECT_EQ("", response_data1); |
| 2366 | // Deleting the transaction attempts to release the socket back into the |
| 2367 | // socket pool. |
| 2368 | trans1.reset(); |
| 2369 | |
| 2370 | HttpRequestInfo request2; |
| 2371 | request2.method = "GET"; |
| 2372 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2373 | request2.traffic_annotation = |
| 2374 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2375 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2376 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2377 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2378 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2379 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2380 | |
| 2381 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2382 | ASSERT_TRUE(response2); |
| 2383 | ASSERT_TRUE(response2->headers); |
| 2384 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2385 | |
| 2386 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2387 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2388 | EXPECT_EQ("foo", response_data2); |
| 2389 | } |
| 2390 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2391 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2392 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2393 | MockWrite data_writes1[] = { |
| 2394 | MockWrite("GET / HTTP/1.1\r\n" |
| 2395 | "Host: www.borked.com\r\n" |
| 2396 | "Connection: keep-alive\r\n\r\n"), |
| 2397 | }; |
| 2398 | |
| 2399 | MockRead data_reads1[] = { |
| 2400 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2401 | "Connection: keep-alive\r\n" |
| 2402 | "Content-Length: 22\r\n\r\n" |
| 2403 | "This server is borked." |
| 2404 | "Bonus data!"), |
| 2405 | }; |
| 2406 | |
| 2407 | MockWrite data_writes2[] = { |
| 2408 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2409 | "Host: www.borked.com\r\n" |
| 2410 | "Connection: keep-alive\r\n\r\n"), |
| 2411 | }; |
| 2412 | |
| 2413 | MockRead data_reads2[] = { |
| 2414 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2415 | "Content-Length: 3\r\n\r\n" |
| 2416 | "foo"), |
| 2417 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2418 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2419 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2420 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2421 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2422 | |
| 2423 | TestCompletionCallback callback; |
| 2424 | HttpRequestInfo request1; |
| 2425 | request1.method = "GET"; |
| 2426 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2427 | request1.traffic_annotation = |
| 2428 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2429 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2430 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2431 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2432 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2433 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2434 | |
| 2435 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2436 | ASSERT_TRUE(response1); |
| 2437 | ASSERT_TRUE(response1->headers); |
| 2438 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2439 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2440 | |
| 2441 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2442 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2443 | EXPECT_EQ("This server is borked.", response_data1); |
| 2444 | // Deleting the transaction attempts to release the socket back into the |
| 2445 | // socket pool. |
| 2446 | trans1.reset(); |
| 2447 | |
| 2448 | HttpRequestInfo request2; |
| 2449 | request2.method = "GET"; |
| 2450 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2451 | request2.traffic_annotation = |
| 2452 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2453 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2454 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2455 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2456 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2457 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2458 | |
| 2459 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2460 | ASSERT_TRUE(response2); |
| 2461 | ASSERT_TRUE(response2->headers); |
| 2462 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2463 | |
| 2464 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2465 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2466 | EXPECT_EQ("foo", response_data2); |
| 2467 | } |
| 2468 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2469 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2470 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2471 | MockWrite data_writes1[] = { |
| 2472 | MockWrite("GET / HTTP/1.1\r\n" |
| 2473 | "Host: www.borked.com\r\n" |
| 2474 | "Connection: keep-alive\r\n\r\n"), |
| 2475 | }; |
| 2476 | |
| 2477 | MockRead data_reads1[] = { |
| 2478 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2479 | "Connection: keep-alive\r\n" |
| 2480 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2481 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2482 | MockRead("0\r\n\r\nBonus data!"), |
| 2483 | }; |
| 2484 | |
| 2485 | MockWrite data_writes2[] = { |
| 2486 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2487 | "Host: www.borked.com\r\n" |
| 2488 | "Connection: keep-alive\r\n\r\n"), |
| 2489 | }; |
| 2490 | |
| 2491 | MockRead data_reads2[] = { |
| 2492 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2493 | "Content-Length: 3\r\n\r\n" |
| 2494 | "foo"), |
| 2495 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2496 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2497 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2498 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2499 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2500 | |
| 2501 | TestCompletionCallback callback; |
| 2502 | HttpRequestInfo request1; |
| 2503 | request1.method = "GET"; |
| 2504 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2505 | request1.traffic_annotation = |
| 2506 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2507 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2508 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2509 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2510 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2511 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2512 | |
| 2513 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2514 | ASSERT_TRUE(response1); |
| 2515 | ASSERT_TRUE(response1->headers); |
| 2516 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2517 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2518 | |
| 2519 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2520 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2521 | EXPECT_EQ("This server is borked.", response_data1); |
| 2522 | // Deleting the transaction attempts to release the socket back into the |
| 2523 | // socket pool. |
| 2524 | trans1.reset(); |
| 2525 | |
| 2526 | HttpRequestInfo request2; |
| 2527 | request2.method = "GET"; |
| 2528 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2529 | request2.traffic_annotation = |
| 2530 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2531 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2532 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2533 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2534 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2535 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2536 | |
| 2537 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2538 | ASSERT_TRUE(response2); |
| 2539 | ASSERT_TRUE(response2->headers); |
| 2540 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2541 | |
| 2542 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2543 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2544 | EXPECT_EQ("foo", response_data2); |
| 2545 | } |
| 2546 | |
| 2547 | // This is a little different from the others - it tests the case that the |
| 2548 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2549 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2550 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2551 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2552 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2553 | MockWrite data_writes1[] = { |
| 2554 | MockWrite("GET / HTTP/1.1\r\n" |
| 2555 | "Host: www.borked.com\r\n" |
| 2556 | "Connection: keep-alive\r\n\r\n"), |
| 2557 | }; |
| 2558 | |
| 2559 | MockRead data_reads1[] = { |
| 2560 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2561 | "Connection: keep-alive\r\n" |
| 2562 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2563 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2564 | MockRead("0\r\n\r\nBonus data!"), |
| 2565 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2566 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2567 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2568 | |
| 2569 | TestCompletionCallback callback; |
| 2570 | HttpRequestInfo request1; |
| 2571 | request1.method = "GET"; |
| 2572 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2573 | request1.traffic_annotation = |
| 2574 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2575 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2576 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2577 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2578 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2579 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2580 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2581 | const HttpResponseInfo* response1 = trans->GetResponseInfo(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2582 | ASSERT_TRUE(response1); |
| 2583 | ASSERT_TRUE(response1->headers); |
| 2584 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2585 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2586 | |
| 2587 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2588 | // response body. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2589 | trans.reset(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2590 | |
| 2591 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2592 | // socket can't be reused, rather than returning it to the socket pool. |
| 2593 | base::RunLoop().RunUntilIdle(); |
| 2594 | |
| 2595 | // There should be no idle sockets in the pool. |
| 2596 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2597 | } |
| 2598 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2599 | // Test the request-challenge-retry sequence for basic auth. |
| 2600 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2601 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2602 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2603 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2604 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2605 | request.traffic_annotation = |
| 2606 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2607 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2608 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2609 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2610 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2611 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2612 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2613 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2614 | MockWrite( |
| 2615 | "GET / HTTP/1.1\r\n" |
| 2616 | "Host: www.example.org\r\n" |
| 2617 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2618 | }; |
| 2619 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2620 | MockRead data_reads1[] = { |
| 2621 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2622 | // Give a couple authenticate options (only the middle one is actually |
| 2623 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2624 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2625 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2626 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2627 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2628 | // Large content-length -- won't matter, as connection will be reset. |
| 2629 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2630 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2631 | }; |
| 2632 | |
| 2633 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2634 | // be issuing -- the final header line contains the credentials. |
| 2635 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2636 | MockWrite( |
| 2637 | "GET / HTTP/1.1\r\n" |
| 2638 | "Host: www.example.org\r\n" |
| 2639 | "Connection: keep-alive\r\n" |
| 2640 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2641 | }; |
| 2642 | |
| 2643 | // Lastly, the server responds with the actual content. |
| 2644 | MockRead data_reads2[] = { |
| 2645 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2646 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2647 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2648 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2649 | }; |
| 2650 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2651 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2652 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2653 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2654 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2655 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2656 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2657 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2658 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2659 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2660 | |
| 2661 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2662 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2663 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2664 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2665 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2666 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2667 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2668 | int64_t writes_size1 = CountWriteBytes(data_writes1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2669 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2670 | int64_t reads_size1 = CountReadBytes(data_reads1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2671 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2672 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2673 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2674 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2675 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2676 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2677 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2678 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2679 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2680 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2681 | |
| 2682 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2683 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2684 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2685 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2686 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2687 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2688 | // The load timing after restart should have a new socket ID, and times after |
| 2689 | // those of the first load timing. |
| 2690 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2691 | load_timing_info2.connect_timing.connect_start); |
| 2692 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2693 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2694 | int64_t writes_size2 = CountWriteBytes(data_writes2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2695 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2696 | int64_t reads_size2 = CountReadBytes(data_reads2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2697 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2698 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2699 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2700 | ASSERT_TRUE(response); |
| 2701 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2702 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2703 | } |
| 2704 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2705 | // Test the request-challenge-retry sequence for basic auth. |
| 2706 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2707 | TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2708 | HttpRequestInfo request; |
| 2709 | request.method = "GET"; |
| 2710 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2711 | request.traffic_annotation = |
| 2712 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2713 | |
| 2714 | TestNetLog log; |
| 2715 | MockHostResolver* resolver = new MockHostResolver(); |
| 2716 | session_deps_.net_log = &log; |
| 2717 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2718 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2719 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2720 | |
| 2721 | resolver->rules()->ClearRules(); |
| 2722 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2723 | |
| 2724 | MockWrite data_writes1[] = { |
| 2725 | MockWrite("GET / HTTP/1.1\r\n" |
| 2726 | "Host: www.example.org\r\n" |
| 2727 | "Connection: keep-alive\r\n\r\n"), |
| 2728 | }; |
| 2729 | |
| 2730 | MockRead data_reads1[] = { |
| 2731 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2732 | // Give a couple authenticate options (only the middle one is actually |
| 2733 | // supported). |
| 2734 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2735 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2736 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2737 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2738 | // Large content-length -- won't matter, as connection will be reset. |
| 2739 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2740 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2741 | }; |
| 2742 | |
| 2743 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2744 | // be issuing -- the final header line contains the credentials. |
| 2745 | MockWrite data_writes2[] = { |
| 2746 | MockWrite("GET / HTTP/1.1\r\n" |
| 2747 | "Host: www.example.org\r\n" |
| 2748 | "Connection: keep-alive\r\n" |
| 2749 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2750 | }; |
| 2751 | |
| 2752 | // Lastly, the server responds with the actual content. |
| 2753 | MockRead data_reads2[] = { |
| 2754 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2755 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2756 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2757 | }; |
| 2758 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2759 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2760 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2761 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2762 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2763 | |
| 2764 | TestCompletionCallback callback1; |
| 2765 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2766 | EXPECT_EQ(OK, callback1.GetResult(trans.Start(&request, callback1.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2767 | NetLogWithSource()))); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2768 | |
| 2769 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2770 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2771 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2772 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2773 | int64_t writes_size1 = CountWriteBytes(data_writes1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2774 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2775 | int64_t reads_size1 = CountReadBytes(data_reads1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2776 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2777 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2778 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2779 | ASSERT_TRUE(response); |
| 2780 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2781 | |
| 2782 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2783 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2784 | ASSERT_FALSE(endpoint.address().empty()); |
| 2785 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2786 | |
| 2787 | resolver->rules()->ClearRules(); |
| 2788 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2789 | |
| 2790 | TestCompletionCallback callback2; |
| 2791 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2792 | EXPECT_EQ(OK, callback2.GetResult(trans.RestartWithAuth( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2793 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2794 | |
| 2795 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2796 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2797 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2798 | // The load timing after restart should have a new socket ID, and times after |
| 2799 | // those of the first load timing. |
| 2800 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2801 | load_timing_info2.connect_timing.connect_start); |
| 2802 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2803 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2804 | int64_t writes_size2 = CountWriteBytes(data_writes2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2805 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2806 | int64_t reads_size2 = CountReadBytes(data_reads2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2807 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2808 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2809 | response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2810 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2811 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2812 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2813 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2814 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2815 | ASSERT_FALSE(endpoint.address().empty()); |
| 2816 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2817 | } |
| 2818 | |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2819 | // Test that, if the server requests auth indefinitely, HttpNetworkTransaction |
| 2820 | // will eventually give up. |
| 2821 | TEST_F(HttpNetworkTransactionTest, BasicAuthForever) { |
| 2822 | HttpRequestInfo request; |
| 2823 | request.method = "GET"; |
| 2824 | request.url = GURL("http://www.example.org/"); |
| 2825 | request.traffic_annotation = |
| 2826 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 2827 | |
| 2828 | TestNetLog log; |
| 2829 | session_deps_.net_log = &log; |
| 2830 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2831 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 2832 | |
| 2833 | MockWrite data_writes[] = { |
| 2834 | MockWrite("GET / HTTP/1.1\r\n" |
| 2835 | "Host: www.example.org\r\n" |
| 2836 | "Connection: keep-alive\r\n\r\n"), |
| 2837 | }; |
| 2838 | |
| 2839 | MockRead data_reads[] = { |
| 2840 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2841 | // Give a couple authenticate options (only the middle one is actually |
| 2842 | // supported). |
| 2843 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2844 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2845 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2846 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2847 | // Large content-length -- won't matter, as connection will be reset. |
| 2848 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2849 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2850 | }; |
| 2851 | |
| 2852 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2853 | // be issuing -- the final header line contains the credentials. |
| 2854 | MockWrite data_writes_restart[] = { |
| 2855 | MockWrite("GET / HTTP/1.1\r\n" |
| 2856 | "Host: www.example.org\r\n" |
| 2857 | "Connection: keep-alive\r\n" |
| 2858 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2859 | }; |
| 2860 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2861 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2862 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2863 | |
| 2864 | TestCompletionCallback callback; |
| 2865 | int rv = callback.GetResult( |
| 2866 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 2867 | |
| 2868 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_restarts; |
| 2869 | for (int i = 0; i < 32; i++) { |
| 2870 | // Check the previous response was a 401. |
| 2871 | EXPECT_THAT(rv, IsOk()); |
| 2872 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 2873 | ASSERT_TRUE(response); |
| 2874 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2875 | |
| 2876 | data_restarts.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2877 | data_reads, data_writes_restart)); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2878 | session_deps_.socket_factory->AddSocketDataProvider( |
| 2879 | data_restarts.back().get()); |
| 2880 | rv = callback.GetResult(trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2881 | callback.callback())); |
| 2882 | } |
| 2883 | |
| 2884 | // After too many tries, the transaction should have given up. |
| 2885 | EXPECT_THAT(rv, IsError(ERR_TOO_MANY_RETRIES)); |
| 2886 | } |
| 2887 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2888 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2889 | HttpRequestInfo request; |
| 2890 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2891 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2892 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2893 | request.traffic_annotation = |
| 2894 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2895 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2896 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2897 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2898 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2899 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2900 | MockWrite( |
| 2901 | "GET / HTTP/1.1\r\n" |
| 2902 | "Host: www.example.org\r\n" |
| 2903 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2904 | }; |
| 2905 | |
| 2906 | MockRead data_reads[] = { |
| 2907 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2908 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2909 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2910 | // Large content-length -- won't matter, as connection will be reset. |
| 2911 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2912 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2913 | }; |
| 2914 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2915 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2916 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2917 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2918 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2919 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2920 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2921 | |
| 2922 | rv = callback.WaitForResult(); |
| 2923 | EXPECT_EQ(0, rv); |
| 2924 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2925 | int64_t writes_size = CountWriteBytes(data_writes); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2926 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2927 | int64_t reads_size = CountReadBytes(data_reads); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2928 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2929 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2930 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2931 | ASSERT_TRUE(response); |
| 2932 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2933 | } |
| 2934 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2935 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2936 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2937 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2938 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2939 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2940 | // reused. See http://crbug.com/544255. |
| 2941 | for (int i = 0; i < 2; ++i) { |
| 2942 | HttpRequestInfo request; |
| 2943 | request.method = "GET"; |
| 2944 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2945 | request.traffic_annotation = |
| 2946 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2947 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2948 | TestNetLog log; |
| 2949 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2950 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2951 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2952 | MockWrite data_writes[] = { |
| 2953 | MockWrite(ASYNC, 0, |
| 2954 | "GET / HTTP/1.1\r\n" |
| 2955 | "Host: www.example.org\r\n" |
| 2956 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2957 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2958 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2959 | // be issuing -- the final header line contains the credentials. |
| 2960 | MockWrite(ASYNC, 6, |
| 2961 | "GET / HTTP/1.1\r\n" |
| 2962 | "Host: www.example.org\r\n" |
| 2963 | "Connection: keep-alive\r\n" |
| 2964 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2965 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2966 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2967 | MockRead data_reads[] = { |
| 2968 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2969 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2970 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2971 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2972 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2973 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2974 | // Lastly, the server responds with the actual content. |
| 2975 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2976 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2977 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2978 | MockRead(ASYNC, 10, "Hello"), |
| 2979 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2980 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2981 | SequencedSocketData data(data_reads, data_writes); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2982 | data.set_busy_before_sync_reads(true); |
| 2983 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2984 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2985 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2986 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2987 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2988 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2989 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2990 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2991 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2992 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2993 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2994 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2995 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2996 | ASSERT_TRUE(response); |
| 2997 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2998 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2999 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3000 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3001 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 3002 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3003 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3004 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3005 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3006 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3007 | TestLoadTimingReused(load_timing_info2); |
| 3008 | // The load timing after restart should have the same socket ID, and times |
| 3009 | // those of the first load timing. |
| 3010 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 3011 | load_timing_info2.send_start); |
| 3012 | 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] | 3013 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3014 | response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3015 | ASSERT_TRUE(response); |
| 3016 | EXPECT_FALSE(response->auth_challenge); |
| 3017 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3018 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3019 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3020 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3021 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3022 | int64_t writes_size = CountWriteBytes(data_writes); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3023 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3024 | int64_t reads_size = CountReadBytes(data_reads); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3025 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3026 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3027 | } |
| 3028 | |
| 3029 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3030 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3031 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3032 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3033 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3034 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3035 | request.traffic_annotation = |
| 3036 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3037 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3038 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3039 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3040 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3041 | MockWrite("GET / HTTP/1.1\r\n" |
| 3042 | "Host: www.example.org\r\n" |
| 3043 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3044 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3045 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3046 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3047 | MockWrite("GET / HTTP/1.1\r\n" |
| 3048 | "Host: www.example.org\r\n" |
| 3049 | "Connection: keep-alive\r\n" |
| 3050 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3051 | }; |
| 3052 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3053 | MockRead data_reads1[] = { |
| 3054 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3055 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3056 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3057 | |
| 3058 | // Lastly, the server responds with the actual content. |
| 3059 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3060 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3061 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3062 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3063 | }; |
| 3064 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3065 | // An incorrect reconnect would cause this to be read. |
| 3066 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3067 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3068 | }; |
| 3069 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3070 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3071 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3072 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3073 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3074 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3075 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3076 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3077 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3078 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3079 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3080 | |
| 3081 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3082 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3083 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3084 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3085 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3086 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3087 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3088 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3089 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3090 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3091 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3092 | |
| 3093 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3094 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3095 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3096 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3097 | ASSERT_TRUE(response); |
| 3098 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3099 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3100 | } |
| 3101 | |
| 3102 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3103 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3104 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3105 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3106 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3107 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3108 | request.traffic_annotation = |
| 3109 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3110 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3111 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3112 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3113 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3114 | MockWrite("GET / HTTP/1.1\r\n" |
| 3115 | "Host: www.example.org\r\n" |
| 3116 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3117 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3118 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3119 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3120 | MockWrite("GET / HTTP/1.1\r\n" |
| 3121 | "Host: www.example.org\r\n" |
| 3122 | "Connection: keep-alive\r\n" |
| 3123 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3124 | }; |
| 3125 | |
| 3126 | // Respond with 5 kb of response body. |
| 3127 | std::string large_body_string("Unauthorized"); |
| 3128 | large_body_string.append(5 * 1024, ' '); |
| 3129 | large_body_string.append("\r\n"); |
| 3130 | |
| 3131 | MockRead data_reads1[] = { |
| 3132 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3133 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3134 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3135 | // 5134 = 12 + 5 * 1024 + 2 |
| 3136 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3137 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3138 | |
| 3139 | // Lastly, the server responds with the actual content. |
| 3140 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3141 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3142 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3143 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3144 | }; |
| 3145 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3146 | // An incorrect reconnect would cause this to be read. |
| 3147 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3148 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3149 | }; |
| 3150 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3151 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3152 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3153 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3154 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3155 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3156 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3157 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3158 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3159 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3160 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3161 | |
| 3162 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3163 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3164 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3165 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3166 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3167 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3168 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3169 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3170 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3171 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3172 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3173 | |
| 3174 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3175 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3176 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3177 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3178 | ASSERT_TRUE(response); |
| 3179 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3180 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3181 | } |
| 3182 | |
| 3183 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3184 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3185 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3186 | HttpRequestInfo request; |
| 3187 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3188 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3189 | request.traffic_annotation = |
| 3190 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3191 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3192 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3193 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3194 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3195 | MockWrite( |
| 3196 | "GET / HTTP/1.1\r\n" |
| 3197 | "Host: www.example.org\r\n" |
| 3198 | "Connection: keep-alive\r\n\r\n"), |
| 3199 | // This simulates the seemingly successful write to a closed connection |
| 3200 | // if the bug is not fixed. |
| 3201 | MockWrite( |
| 3202 | "GET / HTTP/1.1\r\n" |
| 3203 | "Host: www.example.org\r\n" |
| 3204 | "Connection: keep-alive\r\n" |
| 3205 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3206 | }; |
| 3207 | |
| 3208 | MockRead data_reads1[] = { |
| 3209 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3210 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3211 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3212 | MockRead("Content-Length: 14\r\n\r\n"), |
| 3213 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3214 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3215 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3216 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3217 | }; |
| 3218 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3219 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3220 | // be issuing -- the final header line contains the credentials. |
| 3221 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3222 | MockWrite( |
| 3223 | "GET / HTTP/1.1\r\n" |
| 3224 | "Host: www.example.org\r\n" |
| 3225 | "Connection: keep-alive\r\n" |
| 3226 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3227 | }; |
| 3228 | |
| 3229 | // Lastly, the server responds with the actual content. |
| 3230 | MockRead data_reads2[] = { |
| 3231 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3232 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3233 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3234 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3235 | }; |
| 3236 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3237 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3238 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3239 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3240 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3241 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3242 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3243 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3244 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3245 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3246 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3247 | |
| 3248 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3249 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3250 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3251 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3252 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3253 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3254 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3255 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3256 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3257 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3258 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3259 | |
| 3260 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3261 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3262 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3263 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3264 | ASSERT_TRUE(response); |
| 3265 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3266 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3267 | } |
| 3268 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3269 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3270 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3271 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3272 | HttpRequestInfo request; |
| 3273 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3274 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3275 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3276 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3277 | request.traffic_annotation = |
| 3278 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3279 | |
| 3280 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3281 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3282 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3283 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3284 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3285 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3286 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3287 | |
| 3288 | // Since we have proxy, should try to establish tunnel. |
| 3289 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3290 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3291 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3292 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3293 | }; |
| 3294 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3295 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3296 | // connection. |
| 3297 | MockRead data_reads1[] = { |
| 3298 | // No credentials. |
| 3299 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 3300 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3301 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3302 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3303 | // Since the first connection couldn't be reused, need to establish another |
| 3304 | // once given credentials. |
| 3305 | MockWrite data_writes2[] = { |
| 3306 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3307 | // be issuing -- the final header line contains the credentials. |
| 3308 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3309 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3310 | "Proxy-Connection: keep-alive\r\n" |
| 3311 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3312 | |
| 3313 | MockWrite("GET / HTTP/1.1\r\n" |
| 3314 | "Host: www.example.org\r\n" |
| 3315 | "Connection: keep-alive\r\n\r\n"), |
| 3316 | }; |
| 3317 | |
| 3318 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3319 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3320 | |
| 3321 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3322 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3323 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3324 | MockRead(SYNCHRONOUS, "hello"), |
| 3325 | }; |
| 3326 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3327 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3328 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3329 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3330 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3331 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3332 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3333 | |
| 3334 | TestCompletionCallback callback1; |
| 3335 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3336 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3337 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3338 | |
| 3339 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3340 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3341 | |
| 3342 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3343 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3344 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3345 | log.GetEntries(&entries); |
| 3346 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3347 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3348 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3349 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3350 | entries, pos, |
| 3351 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3352 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3353 | |
| 3354 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3355 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3356 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3357 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3358 | EXPECT_EQ(407, response->headers->response_code()); |
| 3359 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3360 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3361 | |
| 3362 | LoadTimingInfo load_timing_info; |
| 3363 | // CONNECT requests and responses are handled at the connect job level, so |
| 3364 | // the transaction does not yet have a connection. |
| 3365 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3366 | |
| 3367 | TestCompletionCallback callback2; |
| 3368 | |
| 3369 | rv = |
| 3370 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3371 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3372 | |
| 3373 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3374 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3375 | |
| 3376 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3377 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3378 | |
| 3379 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3380 | EXPECT_EQ(200, response->headers->response_code()); |
| 3381 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3382 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3383 | |
| 3384 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3385 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3386 | |
| 3387 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3388 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3389 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3390 | |
| 3391 | trans.reset(); |
| 3392 | session->CloseAllConnections(); |
| 3393 | } |
| 3394 | |
| 3395 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3396 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3397 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3398 | HttpRequestInfo request; |
| 3399 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3400 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3401 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3402 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3403 | request.traffic_annotation = |
| 3404 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3405 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3406 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3407 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3408 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3409 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3410 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3411 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3412 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3413 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3414 | // Since we have proxy, should try to establish tunnel. |
| 3415 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3416 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3417 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3418 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3419 | }; |
| 3420 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3421 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3422 | // connection. |
| 3423 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3424 | // No credentials. |
| 3425 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3426 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3427 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3428 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3429 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3430 | MockWrite data_writes2[] = { |
| 3431 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3432 | // be issuing -- the final header line contains the credentials. |
| 3433 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3434 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3435 | "Proxy-Connection: keep-alive\r\n" |
| 3436 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3437 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3438 | MockWrite("GET / HTTP/1.1\r\n" |
| 3439 | "Host: www.example.org\r\n" |
| 3440 | "Connection: keep-alive\r\n\r\n"), |
| 3441 | }; |
| 3442 | |
| 3443 | MockRead data_reads2[] = { |
| 3444 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3445 | |
| 3446 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3447 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3448 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3449 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3450 | }; |
| 3451 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3452 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3453 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3454 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3455 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3456 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3457 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3458 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3459 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3460 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3461 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3462 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3463 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3464 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3465 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3466 | |
| 3467 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3468 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3469 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3470 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3471 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3472 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3473 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3474 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3475 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3476 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3477 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3478 | |
| 3479 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3480 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3481 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3482 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3483 | EXPECT_EQ(407, response->headers->response_code()); |
| 3484 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3485 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3486 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3487 | LoadTimingInfo load_timing_info; |
| 3488 | // CONNECT requests and responses are handled at the connect job level, so |
| 3489 | // the transaction does not yet have a connection. |
| 3490 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3491 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3492 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3493 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3494 | rv = trans->RestartWithAuth( |
| 3495 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3496 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3497 | |
| 3498 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3499 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3500 | |
| 3501 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3502 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3503 | |
| 3504 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3505 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3506 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3507 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3508 | |
| 3509 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3510 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3511 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3512 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3513 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3514 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3515 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3516 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3517 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3518 | } |
| 3519 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3520 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3521 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3522 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3523 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3524 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3525 | // reused. See http://crbug.com/544255. |
| 3526 | for (int i = 0; i < 2; ++i) { |
| 3527 | HttpRequestInfo request; |
| 3528 | request.method = "GET"; |
| 3529 | request.url = GURL("https://www.example.org/"); |
| 3530 | // Ensure that proxy authentication is attempted even |
| 3531 | // when the no authentication data flag is set. |
| 3532 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3533 | request.traffic_annotation = |
| 3534 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3535 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3536 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3537 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3538 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3539 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3540 | BoundTestNetLog log; |
| 3541 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3542 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3543 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3544 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3545 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3546 | // Since we have proxy, should try to establish tunnel. |
| 3547 | MockWrite data_writes1[] = { |
| 3548 | MockWrite(ASYNC, 0, |
| 3549 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3550 | "Host: www.example.org:443\r\n" |
| 3551 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3552 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3553 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3554 | // be issuing -- the final header line contains the credentials. |
| 3555 | MockWrite(ASYNC, 3, |
| 3556 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3557 | "Host: www.example.org:443\r\n" |
| 3558 | "Proxy-Connection: keep-alive\r\n" |
| 3559 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3560 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3561 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3562 | // The proxy responds to the connect with a 407, using a persistent |
| 3563 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3564 | MockRead data_reads1[] = { |
| 3565 | // No credentials. |
| 3566 | MockRead(ASYNC, 1, |
| 3567 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3568 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3569 | "Proxy-Connection: keep-alive\r\n" |
| 3570 | "Content-Length: 10\r\n\r\n"), |
| 3571 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3572 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3573 | // Wrong credentials (wrong password). |
| 3574 | MockRead(ASYNC, 4, |
| 3575 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3576 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3577 | "Proxy-Connection: keep-alive\r\n" |
| 3578 | "Content-Length: 10\r\n\r\n"), |
| 3579 | // No response body because the test stops reading here. |
| 3580 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3581 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3582 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3583 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3584 | data1.set_busy_before_sync_reads(true); |
| 3585 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3586 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3587 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3588 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3589 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3590 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3591 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3592 | TestNetLogEntry::List entries; |
| 3593 | log.GetEntries(&entries); |
| 3594 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3595 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3596 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3597 | ExpectLogContainsSomewhere( |
| 3598 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3599 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3600 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3601 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3602 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3603 | ASSERT_TRUE(response); |
| 3604 | ASSERT_TRUE(response->headers); |
| 3605 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3606 | EXPECT_EQ(407, response->headers->response_code()); |
| 3607 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3608 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3609 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3610 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3611 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3612 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3613 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3614 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3615 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3616 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3617 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3618 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3619 | ASSERT_TRUE(response); |
| 3620 | ASSERT_TRUE(response->headers); |
| 3621 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3622 | EXPECT_EQ(407, response->headers->response_code()); |
| 3623 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3624 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3625 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3626 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3627 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3628 | // out of scope. |
| 3629 | session->CloseAllConnections(); |
| 3630 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3631 | } |
| 3632 | |
| 3633 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3634 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3635 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3636 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3637 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3638 | // reused. See http://crbug.com/544255. |
| 3639 | for (int i = 0; i < 2; ++i) { |
| 3640 | HttpRequestInfo request; |
| 3641 | request.method = "GET"; |
| 3642 | request.url = GURL("https://www.example.org/"); |
| 3643 | // Ensure that proxy authentication is attempted even |
| 3644 | // when the no authentication data flag is set. |
| 3645 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3646 | request.traffic_annotation = |
| 3647 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3648 | |
| 3649 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3650 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3651 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3652 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3653 | BoundTestNetLog log; |
| 3654 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3655 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3656 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3657 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3658 | |
| 3659 | // Since we have proxy, should try to establish tunnel. |
| 3660 | MockWrite data_writes1[] = { |
| 3661 | MockWrite(ASYNC, 0, |
| 3662 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3663 | "Host: www.example.org:443\r\n" |
| 3664 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3665 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3666 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3667 | // be issuing -- the final header line contains the credentials. |
| 3668 | MockWrite(ASYNC, 3, |
| 3669 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3670 | "Host: www.example.org:443\r\n" |
| 3671 | "Proxy-Connection: keep-alive\r\n" |
| 3672 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3673 | }; |
| 3674 | |
| 3675 | // The proxy responds to the connect with a 407, using a persistent |
| 3676 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3677 | MockRead data_reads1[] = { |
| 3678 | // No credentials. |
| 3679 | MockRead(ASYNC, 1, |
| 3680 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3681 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3682 | "Content-Length: 10\r\n\r\n"), |
| 3683 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3684 | |
| 3685 | // Wrong credentials (wrong password). |
| 3686 | MockRead(ASYNC, 4, |
| 3687 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3688 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3689 | "Content-Length: 10\r\n\r\n"), |
| 3690 | // No response body because the test stops reading here. |
| 3691 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3692 | }; |
| 3693 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3694 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3695 | data1.set_busy_before_sync_reads(true); |
| 3696 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3697 | |
| 3698 | TestCompletionCallback callback1; |
| 3699 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3700 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3701 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3702 | |
| 3703 | TestNetLogEntry::List entries; |
| 3704 | log.GetEntries(&entries); |
| 3705 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3706 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3707 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3708 | ExpectLogContainsSomewhere( |
| 3709 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3710 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3711 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3712 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3713 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3714 | ASSERT_TRUE(response); |
| 3715 | ASSERT_TRUE(response->headers); |
| 3716 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3717 | EXPECT_EQ(407, response->headers->response_code()); |
| 3718 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3719 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3720 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3721 | |
| 3722 | TestCompletionCallback callback2; |
| 3723 | |
| 3724 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3725 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3726 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3727 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3728 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3729 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3730 | ASSERT_TRUE(response); |
| 3731 | ASSERT_TRUE(response->headers); |
| 3732 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3733 | EXPECT_EQ(407, response->headers->response_code()); |
| 3734 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3735 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3736 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3737 | |
| 3738 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3739 | // out of scope. |
| 3740 | session->CloseAllConnections(); |
| 3741 | } |
| 3742 | } |
| 3743 | |
| 3744 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3745 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3746 | // the case the server sends extra data on the original socket, so it can't be |
| 3747 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3748 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3749 | HttpRequestInfo request; |
| 3750 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3751 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3752 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3753 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3754 | request.traffic_annotation = |
| 3755 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3756 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3757 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3758 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3759 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3760 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3761 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3762 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3763 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3764 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3765 | // Since we have proxy, should try to establish tunnel. |
| 3766 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3767 | MockWrite(ASYNC, 0, |
| 3768 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3769 | "Host: www.example.org:443\r\n" |
| 3770 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3771 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3772 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3773 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3774 | // extra data, so the socket cannot be reused. |
| 3775 | MockRead data_reads1[] = { |
| 3776 | // No credentials. |
| 3777 | MockRead(ASYNC, 1, |
| 3778 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3779 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3780 | "Content-Length: 10\r\n\r\n"), |
| 3781 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3782 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3783 | }; |
| 3784 | |
| 3785 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3786 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3787 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3788 | MockWrite(ASYNC, 0, |
| 3789 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3790 | "Host: www.example.org:443\r\n" |
| 3791 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3792 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3793 | |
| 3794 | MockWrite(ASYNC, 2, |
| 3795 | "GET / HTTP/1.1\r\n" |
| 3796 | "Host: www.example.org\r\n" |
| 3797 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3798 | }; |
| 3799 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3800 | MockRead data_reads2[] = { |
| 3801 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3802 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3803 | MockRead(ASYNC, 3, |
| 3804 | "HTTP/1.1 200 OK\r\n" |
| 3805 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3806 | "Content-Length: 5\r\n\r\n"), |
| 3807 | // No response body because the test stops reading here. |
| 3808 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3809 | }; |
| 3810 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3811 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3812 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3813 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3814 | SequencedSocketData data2(data_reads2, data_writes2); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3815 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3816 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3817 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3818 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3819 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3820 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3821 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3822 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3823 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3824 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3825 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3826 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3827 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3828 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3829 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3830 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3831 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3832 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3833 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3834 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3835 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3836 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3837 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3838 | ASSERT_TRUE(response); |
| 3839 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3840 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3841 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3842 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3843 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3844 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3845 | LoadTimingInfo load_timing_info; |
| 3846 | // CONNECT requests and responses are handled at the connect job level, so |
| 3847 | // the transaction does not yet have a connection. |
| 3848 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3849 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3850 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3851 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3852 | rv = |
| 3853 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3854 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3855 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3856 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3857 | EXPECT_EQ(200, response->headers->response_code()); |
| 3858 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3859 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3860 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3861 | // The password prompt info should not be set. |
| 3862 | EXPECT_FALSE(response->auth_challenge); |
| 3863 | |
| 3864 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3865 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3866 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3867 | |
| 3868 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3869 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3870 | } |
| 3871 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3872 | // Test the case a proxy closes a socket while the challenge body is being |
| 3873 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3874 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3875 | HttpRequestInfo request; |
| 3876 | request.method = "GET"; |
| 3877 | request.url = GURL("https://www.example.org/"); |
| 3878 | // Ensure that proxy authentication is attempted even |
| 3879 | // when the no authentication data flag is set. |
| 3880 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3881 | request.traffic_annotation = |
| 3882 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3883 | |
| 3884 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3885 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3886 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3887 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3888 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3889 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3890 | |
| 3891 | // Since we have proxy, should try to establish tunnel. |
| 3892 | MockWrite data_writes1[] = { |
| 3893 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3894 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3895 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3896 | }; |
| 3897 | |
| 3898 | // The proxy responds to the connect with a 407, using a persistent |
| 3899 | // connection. |
| 3900 | MockRead data_reads1[] = { |
| 3901 | // No credentials. |
| 3902 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3903 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3904 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3905 | // Server hands up in the middle of the body. |
| 3906 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3907 | }; |
| 3908 | |
| 3909 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3910 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3911 | // be issuing -- the final header line contains the credentials. |
| 3912 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3913 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3914 | "Proxy-Connection: keep-alive\r\n" |
| 3915 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3916 | |
| 3917 | MockWrite("GET / HTTP/1.1\r\n" |
| 3918 | "Host: www.example.org\r\n" |
| 3919 | "Connection: keep-alive\r\n\r\n"), |
| 3920 | }; |
| 3921 | |
| 3922 | MockRead data_reads2[] = { |
| 3923 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3924 | |
| 3925 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3926 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3927 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3928 | MockRead(SYNCHRONOUS, "hello"), |
| 3929 | }; |
| 3930 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3931 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3932 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3933 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3934 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3935 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3936 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3937 | |
| 3938 | TestCompletionCallback callback; |
| 3939 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3940 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3941 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3942 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3943 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3944 | ASSERT_TRUE(response); |
| 3945 | ASSERT_TRUE(response->headers); |
| 3946 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3947 | EXPECT_EQ(407, response->headers->response_code()); |
| 3948 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3949 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3950 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3951 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3952 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3953 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3954 | ASSERT_TRUE(response); |
| 3955 | ASSERT_TRUE(response->headers); |
| 3956 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3957 | EXPECT_EQ(200, response->headers->response_code()); |
| 3958 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3959 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3960 | EXPECT_EQ("hello", body); |
| 3961 | } |
| 3962 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3963 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3964 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3965 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3966 | HttpRequestInfo request; |
| 3967 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3968 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3969 | request.traffic_annotation = |
| 3970 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3971 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3972 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3973 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3974 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3975 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3976 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3977 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3978 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3979 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3980 | // Since we have proxy, should try to establish tunnel. |
| 3981 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3982 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3983 | "Host: www.example.org:443\r\n" |
| 3984 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3985 | }; |
| 3986 | |
| 3987 | // The proxy responds to the connect with a 407. |
| 3988 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3989 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3990 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3991 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3992 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3993 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3994 | }; |
| 3995 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3996 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3997 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3998 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3999 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4000 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4001 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4002 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4003 | |
| 4004 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4005 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4006 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4007 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4008 | ASSERT_TRUE(response); |
| 4009 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4010 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4011 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4012 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4013 | |
| 4014 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4015 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4016 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 4017 | |
| 4018 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 4019 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4020 | } |
| 4021 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4022 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 4023 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4024 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4025 | HttpRequestInfo request; |
| 4026 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4027 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4028 | request.traffic_annotation = |
| 4029 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4030 | |
| 4031 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4032 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4033 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4034 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4035 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4036 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4037 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4038 | |
| 4039 | // Since we have proxy, should try to establish tunnel. |
| 4040 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4041 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4042 | "Host: www.example.org:443\r\n" |
| 4043 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4044 | }; |
| 4045 | |
| 4046 | // The proxy responds to the connect with a 407. |
| 4047 | MockRead data_reads[] = { |
| 4048 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4049 | MockRead("X-Foo: bar\r\n"), |
| 4050 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 4051 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4052 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 4053 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4054 | }; |
| 4055 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4056 | StaticSocketDataProvider data(data_reads, data_writes); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4057 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 4058 | |
| 4059 | TestCompletionCallback callback; |
| 4060 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4061 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4062 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4063 | |
| 4064 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4065 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4066 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4067 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4068 | ASSERT_TRUE(response); |
| 4069 | ASSERT_TRUE(response->headers); |
| 4070 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4071 | EXPECT_EQ(407, response->headers->response_code()); |
| 4072 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4073 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 4074 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 4075 | |
| 4076 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4077 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4078 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4079 | |
| 4080 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 4081 | session->CloseAllConnections(); |
| 4082 | } |
| 4083 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4084 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 4085 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4086 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4087 | HttpRequestInfo request; |
| 4088 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4089 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4090 | request.traffic_annotation = |
| 4091 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4092 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4093 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4094 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4095 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4096 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4097 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4098 | MockWrite( |
| 4099 | "GET / HTTP/1.1\r\n" |
| 4100 | "Host: www.example.org\r\n" |
| 4101 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4102 | }; |
| 4103 | |
| 4104 | MockRead data_reads1[] = { |
| 4105 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 4106 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4107 | // Large content-length -- won't matter, as connection will be reset. |
| 4108 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4109 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4110 | }; |
| 4111 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4112 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4113 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4114 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4115 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4116 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4117 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4118 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4119 | |
| 4120 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4121 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4122 | } |
| 4123 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4124 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 4125 | // through a non-authenticating proxy. The request should fail with |
| 4126 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 4127 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 4128 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 4129 | // response came from the proxy or the server, so it is treated as if the proxy |
| 4130 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4131 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4132 | HttpRequestInfo request; |
| 4133 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4134 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4135 | request.traffic_annotation = |
| 4136 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4137 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4138 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4139 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4140 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4141 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4142 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4143 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4144 | // Since we have proxy, should try to establish tunnel. |
| 4145 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4146 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4147 | "Host: www.example.org:443\r\n" |
| 4148 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4149 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4150 | MockWrite("GET / HTTP/1.1\r\n" |
| 4151 | "Host: www.example.org\r\n" |
| 4152 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4153 | }; |
| 4154 | |
| 4155 | MockRead data_reads1[] = { |
| 4156 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4157 | |
| 4158 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 4159 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4160 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4161 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4162 | }; |
| 4163 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4164 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4165 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4166 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4167 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4168 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4169 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4170 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4171 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4172 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4173 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4174 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4175 | |
| 4176 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4177 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 4178 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 4179 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4180 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4181 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 4182 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4183 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 4184 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4185 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 4186 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4187 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4188 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4189 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4190 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4191 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4192 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 4193 | HttpRequestInfo request; |
| 4194 | request.method = "GET"; |
| 4195 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4196 | request.traffic_annotation = |
| 4197 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4198 | |
| 4199 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4200 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4201 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4202 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4203 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4204 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4205 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4206 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4207 | mock_handler->set_allows_default_credentials(true); |
| 4208 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4209 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4210 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4211 | |
| 4212 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4213 | NetLog net_log; |
| 4214 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4215 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4216 | |
| 4217 | // Since we have proxy, should try to establish tunnel. |
| 4218 | MockWrite data_writes1[] = { |
| 4219 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4220 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4221 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4222 | }; |
| 4223 | |
| 4224 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4225 | // connection. |
| 4226 | MockRead data_reads1[] = { |
| 4227 | // No credentials. |
| 4228 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4229 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4230 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4231 | }; |
| 4232 | |
| 4233 | // Since the first connection couldn't be reused, need to establish another |
| 4234 | // once given credentials. |
| 4235 | MockWrite data_writes2[] = { |
| 4236 | // After calling trans->RestartWithAuth(), this is the request we should |
| 4237 | // be issuing -- the final header line contains the credentials. |
| 4238 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4239 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4240 | "Proxy-Connection: keep-alive\r\n" |
| 4241 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4242 | |
| 4243 | MockWrite("GET / HTTP/1.1\r\n" |
| 4244 | "Host: www.example.org\r\n" |
| 4245 | "Connection: keep-alive\r\n\r\n"), |
| 4246 | }; |
| 4247 | |
| 4248 | MockRead data_reads2[] = { |
| 4249 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4250 | |
| 4251 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4252 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4253 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4254 | MockRead(SYNCHRONOUS, "hello"), |
| 4255 | }; |
| 4256 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4257 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4258 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4259 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4260 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4261 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4262 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4263 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4264 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4265 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4266 | |
| 4267 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4268 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4269 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4270 | |
| 4271 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4272 | ASSERT_TRUE(response); |
| 4273 | ASSERT_TRUE(response->headers); |
| 4274 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 4275 | EXPECT_EQ(407, response->headers->response_code()); |
| 4276 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4277 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4278 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4279 | |
| 4280 | LoadTimingInfo load_timing_info; |
| 4281 | // CONNECT requests and responses are handled at the connect job level, so |
| 4282 | // the transaction does not yet have a connection. |
| 4283 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4284 | |
| 4285 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4286 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4287 | response = trans->GetResponseInfo(); |
| 4288 | ASSERT_TRUE(response); |
| 4289 | ASSERT_TRUE(response->headers); |
| 4290 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4291 | EXPECT_EQ(200, response->headers->response_code()); |
| 4292 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4293 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4294 | |
| 4295 | // The password prompt info should not be set. |
| 4296 | EXPECT_FALSE(response->auth_challenge); |
| 4297 | |
| 4298 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4299 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4300 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4301 | |
| 4302 | trans.reset(); |
| 4303 | session->CloseAllConnections(); |
| 4304 | } |
| 4305 | |
| 4306 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4307 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4308 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4309 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 4310 | HttpRequestInfo request; |
| 4311 | request.method = "GET"; |
| 4312 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4313 | request.traffic_annotation = |
| 4314 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4315 | |
| 4316 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4317 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4318 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4319 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4320 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4321 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4322 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4323 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4324 | mock_handler->set_allows_default_credentials(true); |
| 4325 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4326 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4327 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4328 | |
| 4329 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4330 | NetLog net_log; |
| 4331 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4332 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4333 | |
| 4334 | // Should try to establish tunnel. |
| 4335 | MockWrite data_writes1[] = { |
| 4336 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4337 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4338 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4339 | |
| 4340 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4341 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4342 | "Proxy-Connection: keep-alive\r\n" |
| 4343 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4344 | }; |
| 4345 | |
| 4346 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4347 | // connection. |
| 4348 | MockRead data_reads1[] = { |
| 4349 | // No credentials. |
| 4350 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4351 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4352 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4353 | }; |
| 4354 | |
| 4355 | // Since the first connection was closed, need to establish another once given |
| 4356 | // credentials. |
| 4357 | MockWrite data_writes2[] = { |
| 4358 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4359 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4360 | "Proxy-Connection: keep-alive\r\n" |
| 4361 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4362 | |
| 4363 | MockWrite("GET / HTTP/1.1\r\n" |
| 4364 | "Host: www.example.org\r\n" |
| 4365 | "Connection: keep-alive\r\n\r\n"), |
| 4366 | }; |
| 4367 | |
| 4368 | MockRead data_reads2[] = { |
| 4369 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4370 | |
| 4371 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4372 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4373 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4374 | MockRead(SYNCHRONOUS, "hello"), |
| 4375 | }; |
| 4376 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4377 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4378 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4379 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4380 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4381 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4382 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4383 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4384 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4385 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4386 | |
| 4387 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4388 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4389 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4390 | |
| 4391 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4392 | ASSERT_TRUE(response); |
| 4393 | ASSERT_TRUE(response->headers); |
| 4394 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4395 | EXPECT_EQ(407, response->headers->response_code()); |
| 4396 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4397 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4398 | EXPECT_FALSE(response->auth_challenge); |
| 4399 | |
| 4400 | LoadTimingInfo load_timing_info; |
| 4401 | // CONNECT requests and responses are handled at the connect job level, so |
| 4402 | // the transaction does not yet have a connection. |
| 4403 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4404 | |
| 4405 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4406 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4407 | |
| 4408 | response = trans->GetResponseInfo(); |
| 4409 | ASSERT_TRUE(response); |
| 4410 | ASSERT_TRUE(response->headers); |
| 4411 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4412 | EXPECT_EQ(200, response->headers->response_code()); |
| 4413 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4414 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4415 | |
| 4416 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4417 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4418 | |
| 4419 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4420 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4421 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4422 | |
| 4423 | trans.reset(); |
| 4424 | session->CloseAllConnections(); |
| 4425 | } |
| 4426 | |
| 4427 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4428 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4429 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4430 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4431 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4432 | HttpRequestInfo request; |
| 4433 | request.method = "GET"; |
| 4434 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4435 | request.traffic_annotation = |
| 4436 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4437 | |
| 4438 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4439 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4440 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4441 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4442 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4443 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4444 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4445 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4446 | mock_handler->set_allows_default_credentials(true); |
| 4447 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4448 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4449 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4450 | |
| 4451 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4452 | NetLog net_log; |
| 4453 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4454 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4455 | |
| 4456 | // Should try to establish tunnel. |
| 4457 | MockWrite data_writes1[] = { |
| 4458 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4459 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4460 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4461 | |
| 4462 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4463 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4464 | "Proxy-Connection: keep-alive\r\n" |
| 4465 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4466 | }; |
| 4467 | |
| 4468 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4469 | // second request is sent. |
| 4470 | MockRead data_reads1[] = { |
| 4471 | // No credentials. |
| 4472 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4473 | MockRead("Content-Length: 0\r\n"), |
| 4474 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4475 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4476 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4477 | }; |
| 4478 | |
| 4479 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4480 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4481 | // request. |
| 4482 | MockWrite data_writes2[] = { |
| 4483 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4484 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4485 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4486 | }; |
| 4487 | |
| 4488 | // The proxy, having had more than enough of us, just hangs up. |
| 4489 | MockRead data_reads2[] = { |
| 4490 | // No credentials. |
| 4491 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4492 | }; |
| 4493 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4494 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4495 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4496 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4497 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4498 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4499 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4500 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4501 | |
| 4502 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4503 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4504 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4505 | |
| 4506 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4507 | ASSERT_TRUE(response); |
| 4508 | ASSERT_TRUE(response->headers); |
| 4509 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4510 | EXPECT_EQ(407, response->headers->response_code()); |
| 4511 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4512 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4513 | EXPECT_FALSE(response->auth_challenge); |
| 4514 | |
| 4515 | LoadTimingInfo load_timing_info; |
| 4516 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4517 | |
| 4518 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4519 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4520 | |
| 4521 | trans.reset(); |
| 4522 | session->CloseAllConnections(); |
| 4523 | } |
| 4524 | |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 4525 | // This test exercises an odd edge case where the proxy closes the connection |
| 4526 | // after the authentication handshake is complete. Presumably this technique is |
| 4527 | // used in lieu of returning a 403 or 5xx status code when the authentication |
| 4528 | // succeeds, but the user is not authorized to connect to the destination |
| 4529 | // server. There's no standard for what a proxy should do to indicate a blocked |
| 4530 | // site. |
| 4531 | TEST_F(HttpNetworkTransactionTest, |
| 4532 | AuthAllowsDefaultCredentialsTunnelConnectionClosesBeforeBody) { |
| 4533 | HttpRequestInfo request; |
| 4534 | request.method = "GET"; |
| 4535 | request.url = GURL("https://www.example.org/"); |
| 4536 | request.traffic_annotation = |
| 4537 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4538 | |
| 4539 | // Configure against proxy server "myproxy:70". |
| 4540 | session_deps_.proxy_resolution_service = |
| 4541 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4542 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4543 | |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 4544 | // When TLS 1.3 is enabled, spurious connections are made as part of the SSL |
| 4545 | // version interference probes. |
| 4546 | // TODO(crbug.com/906668): Correctly handle version interference probes to |
| 4547 | // test TLS 1.3. |
| 4548 | SSLConfig config; |
| 4549 | config.version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
| 4550 | session_deps_.ssl_config_service = |
| 4551 | std::make_unique<TestSSLConfigService>(config); |
| 4552 | |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 4553 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
| 4554 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4555 | |
| 4556 | // Create two mock AuthHandlers. This is because the transaction gets retried |
| 4557 | // after the first ERR_CONNECTION_CLOSED since it's ambiguous whether there |
| 4558 | // was a real network error. |
| 4559 | // |
| 4560 | // The handlers support both default and explicit credentials. The retry |
| 4561 | // mentioned above should be able to reuse the default identity. Thus there |
| 4562 | // should never be a need to prompt for explicit credentials. |
| 4563 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
| 4564 | mock_handler->set_allows_default_credentials(true); |
| 4565 | mock_handler->set_allows_explicit_credentials(true); |
| 4566 | mock_handler->set_connection_based(true); |
| 4567 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4568 | HttpAuth::AUTH_PROXY); |
| 4569 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
| 4570 | mock_handler->set_allows_default_credentials(true); |
| 4571 | mock_handler->set_allows_explicit_credentials(true); |
| 4572 | mock_handler->set_connection_based(true); |
| 4573 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4574 | HttpAuth::AUTH_PROXY); |
| 4575 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4576 | |
| 4577 | NetLog net_log; |
| 4578 | session_deps_.net_log = &net_log; |
| 4579 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4580 | |
| 4581 | // Data for both sockets. |
| 4582 | // |
| 4583 | // Writes are for the tunnel establishment attempts and the |
| 4584 | // authentication handshake. |
| 4585 | MockWrite data_writes1[] = { |
| 4586 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4587 | "Host: www.example.org:443\r\n" |
| 4588 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4589 | |
| 4590 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4591 | "Host: www.example.org:443\r\n" |
| 4592 | "Proxy-Connection: keep-alive\r\n" |
| 4593 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4594 | |
| 4595 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4596 | "Host: www.example.org:443\r\n" |
| 4597 | "Proxy-Connection: keep-alive\r\n" |
| 4598 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4599 | }; |
| 4600 | |
| 4601 | // The server side of the authentication handshake. Note that the response to |
| 4602 | // the final CONNECT request is ERR_CONNECTION_CLOSED. |
| 4603 | MockRead data_reads1[] = { |
| 4604 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4605 | MockRead("Content-Length: 0\r\n"), |
| 4606 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4607 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4608 | |
| 4609 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4610 | MockRead("Content-Length: 0\r\n"), |
| 4611 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4612 | MockRead("Proxy-Authenticate: Mock foo\r\n\r\n"), |
| 4613 | |
| 4614 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4615 | }; |
| 4616 | |
| 4617 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 4618 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4619 | |
| 4620 | // The second socket is for the reconnection attempt. Data is identical to the |
| 4621 | // first attempt. |
| 4622 | StaticSocketDataProvider data2(data_reads1, data_writes1); |
| 4623 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4624 | |
| 4625 | auto trans = |
| 4626 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 4627 | |
| 4628 | TestCompletionCallback callback; |
| 4629 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4630 | |
| 4631 | // Two rounds per handshake. After one retry, the error is propagated up the |
| 4632 | // stack. |
| 4633 | for (int i = 0; i < 4; ++i) { |
| 4634 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4635 | |
| 4636 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4637 | ASSERT_TRUE(response); |
| 4638 | ASSERT_TRUE(response->headers); |
| 4639 | EXPECT_EQ(407, response->headers->response_code()); |
| 4640 | ASSERT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4641 | |
| 4642 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4643 | } |
| 4644 | |
| 4645 | // One shall be the number thou shalt retry, and the number of the retrying |
| 4646 | // shall be one. Two shalt thou not retry, neither retry thou zero, excepting |
| 4647 | // that thou then proceed to one. Three is right out. Once the number one, |
| 4648 | // being the first number, be reached, then lobbest thou thy |
| 4649 | // ERR_CONNECTION_CLOSED towards they network transaction, who shall snuff it. |
| 4650 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.GetResult(rv)); |
| 4651 | |
| 4652 | trans.reset(); |
| 4653 | session->CloseAllConnections(); |
| 4654 | } |
| 4655 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4656 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4657 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4658 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4659 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4660 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4661 | HttpRequestInfo request; |
| 4662 | request.method = "GET"; |
| 4663 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4664 | request.traffic_annotation = |
| 4665 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4666 | |
| 4667 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4668 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4669 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4670 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4671 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4672 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4673 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4674 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4675 | mock_handler->set_allows_default_credentials(true); |
| 4676 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4677 | HttpAuth::AUTH_PROXY); |
| 4678 | // Add another handler for the second challenge. It supports default |
| 4679 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4680 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4681 | mock_handler->set_allows_default_credentials(true); |
| 4682 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4683 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4684 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4685 | |
| 4686 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4687 | NetLog net_log; |
| 4688 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4689 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4690 | |
| 4691 | // Should try to establish tunnel. |
| 4692 | MockWrite data_writes1[] = { |
| 4693 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4694 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4695 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4696 | }; |
| 4697 | |
| 4698 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4699 | // connection. |
| 4700 | MockRead data_reads1[] = { |
| 4701 | // No credentials. |
| 4702 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4703 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4704 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4705 | }; |
| 4706 | |
| 4707 | // Since the first connection was closed, need to establish another once given |
| 4708 | // credentials. |
| 4709 | MockWrite data_writes2[] = { |
| 4710 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4711 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4712 | "Proxy-Connection: keep-alive\r\n" |
| 4713 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4714 | }; |
| 4715 | |
| 4716 | MockRead data_reads2[] = { |
| 4717 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4718 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4719 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4720 | }; |
| 4721 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4722 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4723 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4724 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4725 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4726 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4727 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4728 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4729 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4730 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4731 | |
| 4732 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4733 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4734 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4735 | |
| 4736 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4737 | ASSERT_TRUE(response); |
| 4738 | ASSERT_TRUE(response->headers); |
| 4739 | EXPECT_EQ(407, response->headers->response_code()); |
| 4740 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4741 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4742 | EXPECT_FALSE(response->auth_challenge); |
| 4743 | |
| 4744 | LoadTimingInfo load_timing_info; |
| 4745 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4746 | |
| 4747 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4748 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4749 | response = trans->GetResponseInfo(); |
| 4750 | ASSERT_TRUE(response); |
| 4751 | ASSERT_TRUE(response->headers); |
| 4752 | EXPECT_EQ(407, response->headers->response_code()); |
| 4753 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4754 | EXPECT_TRUE(response->auth_challenge); |
| 4755 | |
| 4756 | trans.reset(); |
| 4757 | session->CloseAllConnections(); |
| 4758 | } |
| 4759 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4760 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 4761 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 4762 | // unnecessarily invalidated, and that if the server co-operates, the |
| 4763 | // authentication handshake can continue with the same scheme but with a |
| 4764 | // different identity. |
| 4765 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 4766 | HttpRequestInfo request; |
| 4767 | request.method = "GET"; |
| 4768 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4769 | request.traffic_annotation = |
| 4770 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4771 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4772 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4773 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4774 | |
| 4775 | // First handler. Uses default credentials, but barfs at generate auth token. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4776 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4777 | mock_handler->set_allows_default_credentials(true); |
| 4778 | mock_handler->set_allows_explicit_credentials(true); |
| 4779 | mock_handler->set_connection_based(true); |
| 4780 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 4781 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4782 | HttpAuth::AUTH_SERVER); |
| 4783 | |
| 4784 | // Add another handler for the second challenge. It supports default |
| 4785 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4786 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4787 | mock_handler->set_allows_default_credentials(true); |
| 4788 | mock_handler->set_allows_explicit_credentials(true); |
| 4789 | mock_handler->set_connection_based(true); |
| 4790 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4791 | HttpAuth::AUTH_SERVER); |
| 4792 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4793 | |
| 4794 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4795 | |
| 4796 | MockWrite data_writes1[] = { |
| 4797 | MockWrite("GET / HTTP/1.1\r\n" |
| 4798 | "Host: www.example.org\r\n" |
| 4799 | "Connection: keep-alive\r\n\r\n"), |
| 4800 | }; |
| 4801 | |
| 4802 | MockRead data_reads1[] = { |
| 4803 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4804 | "WWW-Authenticate: Mock\r\n" |
| 4805 | "Connection: keep-alive\r\n\r\n"), |
| 4806 | }; |
| 4807 | |
| 4808 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 4809 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 4810 | // transaction procceds without an authorization header. |
| 4811 | MockWrite data_writes2[] = { |
| 4812 | MockWrite("GET / HTTP/1.1\r\n" |
| 4813 | "Host: www.example.org\r\n" |
| 4814 | "Connection: keep-alive\r\n\r\n"), |
| 4815 | }; |
| 4816 | |
| 4817 | MockRead data_reads2[] = { |
| 4818 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4819 | "WWW-Authenticate: Mock\r\n" |
| 4820 | "Connection: keep-alive\r\n\r\n"), |
| 4821 | }; |
| 4822 | |
| 4823 | MockWrite data_writes3[] = { |
| 4824 | MockWrite("GET / HTTP/1.1\r\n" |
| 4825 | "Host: www.example.org\r\n" |
| 4826 | "Connection: keep-alive\r\n" |
| 4827 | "Authorization: auth_token\r\n\r\n"), |
| 4828 | }; |
| 4829 | |
| 4830 | MockRead data_reads3[] = { |
| 4831 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4832 | "Content-Length: 5\r\n" |
| 4833 | "Content-Type: text/plain\r\n" |
| 4834 | "Connection: keep-alive\r\n\r\n" |
| 4835 | "Hello"), |
| 4836 | }; |
| 4837 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4838 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4839 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4840 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4841 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4842 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4843 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4844 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4845 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 4846 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4847 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4848 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4849 | |
| 4850 | TestCompletionCallback callback; |
| 4851 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4852 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4853 | |
| 4854 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4855 | ASSERT_TRUE(response); |
| 4856 | ASSERT_TRUE(response->headers); |
| 4857 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4858 | |
| 4859 | // The following three tests assert that an authentication challenge was |
| 4860 | // received and that the stack is ready to respond to the challenge using |
| 4861 | // ambient credentials. |
| 4862 | EXPECT_EQ(401, response->headers->response_code()); |
| 4863 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4864 | EXPECT_FALSE(response->auth_challenge); |
| 4865 | |
| 4866 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4867 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4868 | response = trans->GetResponseInfo(); |
| 4869 | ASSERT_TRUE(response); |
| 4870 | ASSERT_TRUE(response->headers); |
| 4871 | |
| 4872 | // The following three tests assert that an authentication challenge was |
| 4873 | // received and that the stack needs explicit credentials before it is ready |
| 4874 | // to respond to the challenge. |
| 4875 | EXPECT_EQ(401, response->headers->response_code()); |
| 4876 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4877 | EXPECT_TRUE(response->auth_challenge); |
| 4878 | |
| 4879 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4880 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4881 | response = trans->GetResponseInfo(); |
| 4882 | ASSERT_TRUE(response); |
| 4883 | ASSERT_TRUE(response->headers); |
| 4884 | EXPECT_EQ(200, response->headers->response_code()); |
| 4885 | |
| 4886 | trans.reset(); |
| 4887 | session->CloseAllConnections(); |
| 4888 | } |
| 4889 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4890 | // Proxy resolver that returns a proxy with the same host and port for different |
| 4891 | // schemes, based on the path of the URL being requests. |
| 4892 | class SameProxyWithDifferentSchemesProxyResolver : public ProxyResolver { |
| 4893 | public: |
| 4894 | SameProxyWithDifferentSchemesProxyResolver() {} |
| 4895 | ~SameProxyWithDifferentSchemesProxyResolver() override {} |
| 4896 | |
| 4897 | static std::string ProxyHostPortPairAsString() { return "proxy.test:10000"; } |
| 4898 | |
| 4899 | static HostPortPair ProxyHostPortPair() { |
| 4900 | return HostPortPair::FromString(ProxyHostPortPairAsString()); |
| 4901 | } |
| 4902 | |
| 4903 | // ProxyResolver implementation. |
| 4904 | int GetProxyForURL(const GURL& url, |
| 4905 | ProxyInfo* results, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 4906 | CompletionOnceCallback callback, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4907 | std::unique_ptr<Request>* request, |
| 4908 | const NetLogWithSource& /*net_log*/) override { |
| 4909 | *results = ProxyInfo(); |
Ramin Halavati | 921731ea | 2018-03-16 08:24:57 | [diff] [blame] | 4910 | results->set_traffic_annotation( |
| 4911 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS)); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4912 | if (url.path() == "/socks4") { |
| 4913 | results->UsePacString("SOCKS " + ProxyHostPortPairAsString()); |
| 4914 | return OK; |
| 4915 | } |
| 4916 | if (url.path() == "/socks5") { |
| 4917 | results->UsePacString("SOCKS5 " + ProxyHostPortPairAsString()); |
| 4918 | return OK; |
| 4919 | } |
| 4920 | if (url.path() == "/http") { |
| 4921 | results->UsePacString("PROXY " + ProxyHostPortPairAsString()); |
| 4922 | return OK; |
| 4923 | } |
| 4924 | if (url.path() == "/https") { |
| 4925 | results->UsePacString("HTTPS " + ProxyHostPortPairAsString()); |
| 4926 | return OK; |
| 4927 | } |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 4928 | if (url.path() == "/https_trusted") { |
| 4929 | results->UseProxyServer(ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 4930 | ProxyHostPortPair(), |
| 4931 | true /* is_trusted_proxy */)); |
| 4932 | return OK; |
| 4933 | } |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4934 | NOTREACHED(); |
| 4935 | return ERR_NOT_IMPLEMENTED; |
| 4936 | } |
| 4937 | |
| 4938 | private: |
| 4939 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolver); |
| 4940 | }; |
| 4941 | |
| 4942 | class SameProxyWithDifferentSchemesProxyResolverFactory |
| 4943 | : public ProxyResolverFactory { |
| 4944 | public: |
| 4945 | SameProxyWithDifferentSchemesProxyResolverFactory() |
| 4946 | : ProxyResolverFactory(false) {} |
| 4947 | |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 4948 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 4949 | std::unique_ptr<ProxyResolver>* resolver, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 4950 | CompletionOnceCallback callback, |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 4951 | std::unique_ptr<Request>* request) override { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4952 | *resolver = std::make_unique<SameProxyWithDifferentSchemesProxyResolver>(); |
| 4953 | return OK; |
| 4954 | } |
| 4955 | |
| 4956 | private: |
| 4957 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolverFactory); |
| 4958 | }; |
| 4959 | |
| 4960 | // Check that when different proxy schemes are all applied to a proxy at the |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 4961 | // same address, the connections are not grouped together. i.e., a request to |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4962 | // foo.com using proxy.com as an HTTPS proxy won't use the same socket as a |
| 4963 | // request to foo.com using proxy.com as an HTTP proxy. |
| 4964 | TEST_F(HttpNetworkTransactionTest, SameDestinationForDifferentProxyTypes) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4965 | session_deps_.proxy_resolution_service = |
| 4966 | std::make_unique<ProxyResolutionService>( |
| 4967 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 4968 | ProxyConfig::CreateAutoDetect(), TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 4969 | std::make_unique<SameProxyWithDifferentSchemesProxyResolverFactory>(), |
| 4970 | nullptr); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4971 | |
| 4972 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4973 | |
| 4974 | MockWrite socks_writes[] = { |
| 4975 | MockWrite(SYNCHRONOUS, kSOCKS4OkRequestLocalHostPort80, |
| 4976 | kSOCKS4OkRequestLocalHostPort80Length), |
| 4977 | MockWrite(SYNCHRONOUS, |
| 4978 | "GET /socks4 HTTP/1.1\r\n" |
| 4979 | "Host: test\r\n" |
| 4980 | "Connection: keep-alive\r\n\r\n"), |
| 4981 | }; |
| 4982 | MockRead socks_reads[] = { |
| 4983 | MockRead(SYNCHRONOUS, kSOCKS4OkReply, kSOCKS4OkReplyLength), |
| 4984 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4985 | "Connection: keep-alive\r\n" |
| 4986 | "Content-Length: 15\r\n\r\n" |
| 4987 | "SOCKS4 Response"), |
| 4988 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4989 | StaticSocketDataProvider socks_data(socks_reads, socks_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4990 | session_deps_.socket_factory->AddSocketDataProvider(&socks_data); |
| 4991 | |
| 4992 | const char kSOCKS5Request[] = { |
| 4993 | 0x05, // Version |
| 4994 | 0x01, // Command (CONNECT) |
| 4995 | 0x00, // Reserved |
| 4996 | 0x03, // Address type (DOMAINNAME) |
| 4997 | 0x04, // Length of domain (4) |
| 4998 | 't', 'e', 's', 't', // Domain string |
| 4999 | 0x00, 0x50, // 16-bit port (80) |
| 5000 | }; |
| 5001 | MockWrite socks5_writes[] = { |
| 5002 | MockWrite(ASYNC, kSOCKS5GreetRequest, kSOCKS5GreetRequestLength), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5003 | MockWrite(ASYNC, kSOCKS5Request, base::size(kSOCKS5Request)), |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5004 | MockWrite(SYNCHRONOUS, |
| 5005 | "GET /socks5 HTTP/1.1\r\n" |
| 5006 | "Host: test\r\n" |
| 5007 | "Connection: keep-alive\r\n\r\n"), |
| 5008 | }; |
| 5009 | MockRead socks5_reads[] = { |
| 5010 | MockRead(ASYNC, kSOCKS5GreetResponse, kSOCKS5GreetResponseLength), |
| 5011 | MockRead(ASYNC, kSOCKS5OkResponse, kSOCKS5OkResponseLength), |
| 5012 | MockRead("HTTP/1.0 200 OK\r\n" |
| 5013 | "Connection: keep-alive\r\n" |
| 5014 | "Content-Length: 15\r\n\r\n" |
| 5015 | "SOCKS5 Response"), |
| 5016 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5017 | StaticSocketDataProvider socks5_data(socks5_reads, socks5_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5018 | session_deps_.socket_factory->AddSocketDataProvider(&socks5_data); |
| 5019 | |
| 5020 | MockWrite http_writes[] = { |
| 5021 | MockWrite(SYNCHRONOUS, |
| 5022 | "GET http://test/http HTTP/1.1\r\n" |
| 5023 | "Host: test\r\n" |
| 5024 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5025 | }; |
| 5026 | MockRead http_reads[] = { |
| 5027 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5028 | "Proxy-Connection: keep-alive\r\n" |
| 5029 | "Content-Length: 13\r\n\r\n" |
| 5030 | "HTTP Response"), |
| 5031 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5032 | StaticSocketDataProvider http_data(http_reads, http_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5033 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 5034 | |
| 5035 | MockWrite https_writes[] = { |
| 5036 | MockWrite(SYNCHRONOUS, |
| 5037 | "GET http://test/https HTTP/1.1\r\n" |
| 5038 | "Host: test\r\n" |
| 5039 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5040 | }; |
| 5041 | MockRead https_reads[] = { |
| 5042 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5043 | "Proxy-Connection: keep-alive\r\n" |
| 5044 | "Content-Length: 14\r\n\r\n" |
| 5045 | "HTTPS Response"), |
| 5046 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5047 | StaticSocketDataProvider https_data(https_reads, https_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5048 | session_deps_.socket_factory->AddSocketDataProvider(&https_data); |
| 5049 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 5050 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5051 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5052 | MockWrite https_trusted_writes[] = { |
| 5053 | MockWrite(SYNCHRONOUS, |
| 5054 | "GET http://test/https_trusted HTTP/1.1\r\n" |
| 5055 | "Host: test\r\n" |
| 5056 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5057 | }; |
| 5058 | MockRead https_trusted_reads[] = { |
| 5059 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5060 | "Proxy-Connection: keep-alive\r\n" |
| 5061 | "Content-Length: 22\r\n\r\n" |
| 5062 | "HTTPS Trusted Response"), |
| 5063 | }; |
| 5064 | StaticSocketDataProvider trusted_https_data(https_trusted_reads, |
| 5065 | https_trusted_writes); |
| 5066 | session_deps_.socket_factory->AddSocketDataProvider(&trusted_https_data); |
| 5067 | SSLSocketDataProvider ssl2(SYNCHRONOUS, OK); |
| 5068 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 5069 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5070 | struct TestCase { |
| 5071 | GURL url; |
| 5072 | std::string expected_response; |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5073 | // How many idle sockets there should be in the SOCKS 4/5 proxy socket pools |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5074 | // after the test. |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5075 | int expected_idle_socks4_sockets; |
| 5076 | int expected_idle_socks5_sockets; |
| 5077 | // How many idle sockets there should be in the HTTP/HTTPS proxy socket |
| 5078 | // pools after the test. |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5079 | int expected_idle_http_sockets; |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5080 | int expected_idle_https_sockets; |
| 5081 | // How many idle sockets there should be in the HTTPS proxy socket pool with |
| 5082 | // the ProxyServer's |is_trusted_proxy| bit set after the test. |
| 5083 | int expected_idle_trusted_https_sockets; |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5084 | } const kTestCases[] = { |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5085 | {GURL("http://test/socks4"), "SOCKS4 Response", 1, 0, 0, 0, 0}, |
| 5086 | {GURL("http://test/socks5"), "SOCKS5 Response", 1, 1, 0, 0, 0}, |
| 5087 | {GURL("http://test/http"), "HTTP Response", 1, 1, 1, 0, 0}, |
| 5088 | {GURL("http://test/https"), "HTTPS Response", 1, 1, 1, 1, 0}, |
| 5089 | {GURL("http://test/https_trusted"), "HTTPS Trusted Response", 1, 1, 1, 1, |
| 5090 | 1}, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5091 | }; |
| 5092 | |
| 5093 | for (const auto& test_case : kTestCases) { |
| 5094 | HttpRequestInfo request; |
| 5095 | request.method = "GET"; |
| 5096 | request.url = test_case.url; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5097 | request.traffic_annotation = |
| 5098 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5099 | std::unique_ptr<HttpNetworkTransaction> trans = |
| 5100 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 5101 | session.get()); |
| 5102 | TestCompletionCallback callback; |
| 5103 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 5104 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5105 | |
| 5106 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5107 | ASSERT_TRUE(response); |
| 5108 | ASSERT_TRUE(response->headers); |
| 5109 | EXPECT_EQ(200, response->headers->response_code()); |
| 5110 | std::string response_data; |
| 5111 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 5112 | EXPECT_EQ(test_case.expected_response, response_data); |
| 5113 | |
| 5114 | // Return the socket to the socket pool, so can make sure it's not used for |
| 5115 | // the next requests. |
| 5116 | trans.reset(); |
| 5117 | base::RunLoop().RunUntilIdle(); |
| 5118 | |
| 5119 | // Check the number of idle sockets in the pool, to make sure that used |
| 5120 | // sockets are indeed being returned to the socket pool. If each request |
| 5121 | // doesn't return an idle socket to the pool, the test would incorrectly |
| 5122 | // pass. |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5123 | EXPECT_EQ(test_case.expected_idle_socks4_sockets, |
| 5124 | session |
| 5125 | ->GetSocketPoolForSOCKSProxy( |
| 5126 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5127 | ProxyServer(ProxyServer::SCHEME_SOCKS4, |
| 5128 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5129 | ProxyHostPortPair())) |
| 5130 | ->IdleSocketCount()); |
| 5131 | EXPECT_EQ(test_case.expected_idle_socks5_sockets, |
| 5132 | session |
| 5133 | ->GetSocketPoolForSOCKSProxy( |
| 5134 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5135 | ProxyServer(ProxyServer::SCHEME_SOCKS5, |
| 5136 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5137 | ProxyHostPortPair())) |
| 5138 | ->IdleSocketCount()); |
| 5139 | EXPECT_EQ(test_case.expected_idle_http_sockets, |
| 5140 | session |
| 5141 | ->GetSocketPoolForHTTPLikeProxy( |
| 5142 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5143 | ProxyServer(ProxyServer::SCHEME_HTTP, |
| 5144 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5145 | ProxyHostPortPair())) |
| 5146 | ->IdleSocketCount()); |
| 5147 | EXPECT_EQ(test_case.expected_idle_https_sockets, |
| 5148 | session |
| 5149 | ->GetSocketPoolForHTTPLikeProxy( |
| 5150 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5151 | ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 5152 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5153 | ProxyHostPortPair())) |
| 5154 | ->IdleSocketCount()); |
| 5155 | EXPECT_EQ(test_case.expected_idle_trusted_https_sockets, |
| 5156 | session |
| 5157 | ->GetSocketPoolForHTTPLikeProxy( |
| 5158 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5159 | ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 5160 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5161 | ProxyHostPortPair(), |
| 5162 | true /* is_trusted_proxy */)) |
| 5163 | ->IdleSocketCount()); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5164 | } |
| 5165 | } |
| 5166 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5167 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5168 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5169 | HttpRequestInfo request1; |
| 5170 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5171 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5172 | request1.traffic_annotation = |
| 5173 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5174 | |
| 5175 | HttpRequestInfo request2; |
| 5176 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5177 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5178 | request2.traffic_annotation = |
| 5179 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5180 | |
| 5181 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5182 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5183 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5184 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5185 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5186 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5187 | |
| 5188 | // Since we have proxy, should try to establish tunnel. |
| 5189 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5190 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5191 | "Host: www.example.org:443\r\n" |
| 5192 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5193 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5194 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 5195 | "Host: www.example.org\r\n" |
| 5196 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5197 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5198 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 5199 | "Host: www.example.org\r\n" |
| 5200 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5201 | }; |
| 5202 | |
| 5203 | // The proxy responds to the connect with a 407, using a persistent |
| 5204 | // connection. |
| 5205 | MockRead data_reads1[] = { |
| 5206 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 5207 | |
| 5208 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5209 | MockRead("Content-Length: 1\r\n\r\n"), |
| 5210 | MockRead(SYNCHRONOUS, "1"), |
| 5211 | |
| 5212 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5213 | MockRead("Content-Length: 2\r\n\r\n"), |
| 5214 | MockRead(SYNCHRONOUS, "22"), |
| 5215 | }; |
| 5216 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5217 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5218 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5219 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5220 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5221 | |
| 5222 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5223 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5224 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5225 | |
| 5226 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5227 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5228 | |
| 5229 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5230 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5231 | |
| 5232 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5233 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5234 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5235 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5236 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 5237 | |
| 5238 | LoadTimingInfo load_timing_info1; |
| 5239 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 5240 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5241 | |
| 5242 | trans1.reset(); |
| 5243 | |
| 5244 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5245 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5246 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5247 | |
| 5248 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5249 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5250 | |
| 5251 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5252 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5253 | |
| 5254 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5255 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5256 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5257 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5258 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 5259 | |
| 5260 | LoadTimingInfo load_timing_info2; |
| 5261 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5262 | TestLoadTimingReused(load_timing_info2); |
| 5263 | |
| 5264 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 5265 | |
| 5266 | trans2.reset(); |
| 5267 | session->CloseAllConnections(); |
| 5268 | } |
| 5269 | |
| 5270 | // Test the load timing for HTTPS requests with an HTTP proxy and a PAC script. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5271 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5272 | HttpRequestInfo request1; |
| 5273 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5274 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5275 | request1.traffic_annotation = |
| 5276 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5277 | |
| 5278 | HttpRequestInfo request2; |
| 5279 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5280 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5281 | request2.traffic_annotation = |
| 5282 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5283 | |
| 5284 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5285 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5286 | ProxyResolutionService::CreateFixedFromPacResult( |
| 5287 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5288 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5289 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5290 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5291 | |
| 5292 | // Since we have proxy, should try to establish tunnel. |
| 5293 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5294 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5295 | "Host: www.example.org:443\r\n" |
| 5296 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5297 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5298 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 5299 | "Host: www.example.org\r\n" |
| 5300 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5301 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5302 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 5303 | "Host: www.example.org\r\n" |
| 5304 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5305 | }; |
| 5306 | |
| 5307 | // The proxy responds to the connect with a 407, using a persistent |
| 5308 | // connection. |
| 5309 | MockRead data_reads1[] = { |
| 5310 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 5311 | |
| 5312 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5313 | MockRead("Content-Length: 1\r\n\r\n"), |
| 5314 | MockRead(SYNCHRONOUS, "1"), |
| 5315 | |
| 5316 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5317 | MockRead("Content-Length: 2\r\n\r\n"), |
| 5318 | MockRead(SYNCHRONOUS, "22"), |
| 5319 | }; |
| 5320 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5321 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5322 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5323 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5324 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5325 | |
| 5326 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5327 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5328 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5329 | |
| 5330 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5331 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5332 | |
| 5333 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5334 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5335 | |
| 5336 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5337 | ASSERT_TRUE(response1); |
| 5338 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5339 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 5340 | |
| 5341 | LoadTimingInfo load_timing_info1; |
| 5342 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 5343 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 5344 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 5345 | |
| 5346 | trans1.reset(); |
| 5347 | |
| 5348 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5349 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5350 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5351 | |
| 5352 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5353 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5354 | |
| 5355 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5356 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5357 | |
| 5358 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5359 | ASSERT_TRUE(response2); |
| 5360 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5361 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 5362 | |
| 5363 | LoadTimingInfo load_timing_info2; |
| 5364 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5365 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 5366 | |
| 5367 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 5368 | |
| 5369 | trans2.reset(); |
| 5370 | session->CloseAllConnections(); |
| 5371 | } |
| 5372 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5373 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5374 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5375 | HttpRequestInfo request; |
| 5376 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5377 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5378 | request.traffic_annotation = |
| 5379 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5380 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5381 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5382 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5383 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5384 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5385 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5386 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5387 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5388 | // Since we have proxy, should use full url |
| 5389 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5390 | MockWrite( |
| 5391 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5392 | "Host: www.example.org\r\n" |
| 5393 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5394 | }; |
| 5395 | |
| 5396 | MockRead data_reads1[] = { |
| 5397 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5398 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5399 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5400 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5401 | }; |
| 5402 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5403 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5404 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5405 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5406 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5407 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5408 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5409 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5410 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5411 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5412 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5413 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5414 | |
| 5415 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5416 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5417 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5418 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5419 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5420 | TestLoadTimingNotReused(load_timing_info, |
| 5421 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5422 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5423 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5424 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5425 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5426 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5427 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5428 | EXPECT_EQ(200, response->headers->response_code()); |
| 5429 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5430 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5431 | |
| 5432 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5433 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5434 | } |
| 5435 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5436 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5437 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5438 | HttpRequestInfo request; |
| 5439 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5440 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5441 | request.traffic_annotation = |
| 5442 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5443 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5444 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5445 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5446 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5447 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5448 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5449 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5450 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5451 | // fetch http://www.example.org/ via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5452 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5453 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5454 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5455 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5456 | spdy::SpdySerializedFrame resp( |
| 5457 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 5458 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5459 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5460 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5461 | }; |
| 5462 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5463 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5464 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5465 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5466 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5467 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5468 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5469 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5470 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5471 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5472 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5473 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5474 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5475 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5476 | |
| 5477 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5478 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5479 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5480 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5481 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5482 | TestLoadTimingNotReused(load_timing_info, |
| 5483 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5484 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5485 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5486 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5487 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5488 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5489 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5490 | |
| 5491 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5492 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5493 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5494 | } |
| 5495 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5496 | // Verifies that a session which races and wins against the owning transaction |
| 5497 | // (completing prior to host resolution), doesn't fail the transaction. |
| 5498 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5499 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5500 | HttpRequestInfo request; |
| 5501 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5502 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5503 | request.traffic_annotation = |
| 5504 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5505 | |
| 5506 | // Configure SPDY proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5507 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5508 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5509 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5510 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5511 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5512 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5513 | // Fetch http://www.example.org/ through the SPDY proxy. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5514 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5515 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5516 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5517 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5518 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 5519 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5520 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5521 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5522 | }; |
| 5523 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5524 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5525 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5526 | |
| 5527 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5528 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5529 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5530 | |
| 5531 | TestCompletionCallback callback1; |
| 5532 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5533 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5534 | |
| 5535 | // Stall the hostname resolution begun by the transaction. |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5536 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5537 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5538 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5539 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5540 | |
| 5541 | // Race a session to the proxy, which completes first. |
| 5542 | session_deps_.host_resolver->set_ondemand_mode(false); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 5543 | SpdySessionKey key(HostPortPair("proxy", 70), ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 5544 | PRIVACY_MODE_DISABLED, |
| 5545 | SpdySessionKey::IsProxySession::kTrue, SocketTag()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5546 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 5547 | CreateSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5548 | |
| 5549 | // Unstall the resolution begun by the transaction. |
| 5550 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5551 | session_deps_.host_resolver->ResolveAllPending(); |
| 5552 | |
| 5553 | EXPECT_FALSE(callback1.have_result()); |
| 5554 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5555 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5556 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5557 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5558 | ASSERT_TRUE(response); |
| 5559 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5560 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5561 | |
| 5562 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5563 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5564 | EXPECT_EQ(kUploadData, response_data); |
| 5565 | } |
| 5566 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5567 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5568 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5569 | HttpRequestInfo request; |
| 5570 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5571 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5572 | request.traffic_annotation = |
| 5573 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5574 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5575 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5576 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5577 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5578 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5579 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5580 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5581 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5582 | // The first request will be a bare GET, the second request will be a |
| 5583 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5584 | spdy_util_.set_default_url(request.url); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5585 | spdy::SpdySerializedFrame req_get( |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5586 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5587 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5588 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5589 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5590 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5591 | spdy::SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5592 | kExtraAuthorizationHeaders, base::size(kExtraAuthorizationHeaders) / 2, 3, |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5593 | LOWEST)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5594 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5595 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5596 | }; |
| 5597 | |
| 5598 | // The first response is a 407 proxy authentication challenge, and the second |
| 5599 | // response will be a 200 response since the second request includes a valid |
| 5600 | // Authorization header. |
| 5601 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5602 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5603 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5604 | spdy::SpdySerializedFrame resp_authentication( |
| 5605 | spdy_util_.ConstructSpdyReplyError( |
| 5606 | "407", kExtraAuthenticationHeaders, |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5607 | base::size(kExtraAuthenticationHeaders) / 2, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5608 | spdy::SpdySerializedFrame body_authentication( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5609 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5610 | spdy::SpdySerializedFrame resp_data( |
| 5611 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 5612 | spdy::SpdySerializedFrame body_data( |
| 5613 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5614 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5615 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5616 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5617 | CreateMockRead(resp_data, 4), |
| 5618 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5619 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5620 | }; |
| 5621 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5622 | SequencedSocketData data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5623 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5624 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5625 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5626 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5627 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5628 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5629 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5630 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5631 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5632 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5633 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5634 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5635 | |
| 5636 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5637 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5638 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5639 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5640 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5641 | ASSERT_TRUE(response); |
| 5642 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5643 | EXPECT_EQ(407, response->headers->response_code()); |
| 5644 | EXPECT_TRUE(response->was_fetched_via_spdy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5645 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5646 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5647 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5648 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5649 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5650 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5651 | |
| 5652 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5653 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5654 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5655 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5656 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5657 | ASSERT_TRUE(response_restart); |
| 5658 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5659 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 5660 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5661 | EXPECT_FALSE(response_restart->auth_challenge); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5662 | } |
| 5663 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5664 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5665 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5666 | HttpRequestInfo request; |
| 5667 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5668 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5669 | request.traffic_annotation = |
| 5670 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5671 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5672 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5673 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5674 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5675 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5676 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5677 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5678 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5679 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5680 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5681 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5682 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5683 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 5684 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5685 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5686 | const char get[] = |
| 5687 | "GET / HTTP/1.1\r\n" |
| 5688 | "Host: www.example.org\r\n" |
| 5689 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5690 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5691 | spdy_util_.ConstructSpdyDataFrame(1, get, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5692 | spdy::SpdySerializedFrame conn_resp( |
| 5693 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5694 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 5695 | "Content-Length: 10\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5696 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5697 | spdy_util_.ConstructSpdyDataFrame(1, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5698 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5699 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5700 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5701 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5702 | |
| 5703 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5704 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5705 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5706 | }; |
| 5707 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5708 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5709 | CreateMockRead(conn_resp, 1, ASYNC), |
| 5710 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 5711 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 5712 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5713 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5714 | }; |
| 5715 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5716 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5717 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5718 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5719 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5720 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5721 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5722 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5723 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5724 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5725 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5726 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5727 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5728 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5729 | |
| 5730 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5731 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5732 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5733 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5734 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5735 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5736 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5737 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5738 | ASSERT_TRUE(response); |
| 5739 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5740 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5741 | |
| 5742 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5743 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5744 | EXPECT_EQ("1234567890", response_data); |
| 5745 | } |
| 5746 | |
| 5747 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5748 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 5749 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5750 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5751 | HttpRequestInfo request; |
| 5752 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5753 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5754 | request.traffic_annotation = |
| 5755 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5756 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5757 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5758 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5759 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5760 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5761 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5762 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5763 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5764 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5765 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5766 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5767 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5768 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 5769 | // fetch https://www.example.org/ via SPDY |
| 5770 | const char kMyUrl[] = "https://www.example.org/"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5771 | spdy::SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5772 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5773 | spdy::SpdySerializedFrame wrapped_get( |
| 5774 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 5775 | spdy::SpdySerializedFrame conn_resp( |
| 5776 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 5777 | spdy::SpdySerializedFrame get_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5778 | spdy_util_wrapped.ConstructSpdyGetReply(NULL, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5779 | spdy::SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5780 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5781 | spdy::SpdySerializedFrame body( |
| 5782 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 5783 | spdy::SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5784 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5785 | spdy::SpdySerializedFrame window_update_get_resp( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5786 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5787 | spdy::SpdySerializedFrame window_update_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5788 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5789 | |
| 5790 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5791 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5792 | CreateMockWrite(window_update_get_resp, 6), |
| 5793 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5794 | }; |
| 5795 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5796 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5797 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5798 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5799 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 5800 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5801 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5802 | }; |
| 5803 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5804 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5805 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5806 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5807 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5808 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5809 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5810 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5811 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5812 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5813 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5814 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5815 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5816 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5817 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5818 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5819 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 5820 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5821 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5822 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5823 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5824 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5825 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5826 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5827 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5828 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5829 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5830 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5831 | ASSERT_TRUE(response); |
| 5832 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5833 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5834 | |
| 5835 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5836 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5837 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5838 | } |
| 5839 | |
| 5840 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5841 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5842 | HttpRequestInfo request; |
| 5843 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5844 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5845 | request.traffic_annotation = |
| 5846 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5847 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5848 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5849 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5850 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5851 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5852 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5853 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5854 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5855 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5856 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5857 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5858 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5859 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5860 | spdy::SpdySerializedFrame get( |
| 5861 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5862 | |
| 5863 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5864 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5865 | }; |
| 5866 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5867 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
| 5868 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5869 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5870 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5871 | }; |
| 5872 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5873 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5874 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5875 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5876 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5877 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5878 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5879 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5880 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5881 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5882 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5883 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5884 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5885 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5886 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5887 | |
| 5888 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5889 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5890 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 5891 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5892 | } |
| 5893 | |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5894 | // Test the case where a proxied H2 session doesn't exist when an auth challenge |
| 5895 | // is observed, but does exist by the time auth credentials are provided. |
| 5896 | // Proxy-Connection: Close is used so that there's a second DNS lookup, which is |
| 5897 | // what causes the existing H2 session to be noticed and reused. |
| 5898 | TEST_F(HttpNetworkTransactionTest, ProxiedH2SessionAppearsDuringAuth) { |
| 5899 | ProxyConfig proxy_config; |
| 5900 | proxy_config.set_auto_detect(true); |
| 5901 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 5902 | |
| 5903 | CapturingProxyResolver capturing_proxy_resolver; |
| 5904 | capturing_proxy_resolver.set_proxy_server( |
| 5905 | ProxyServer(ProxyServer::SCHEME_HTTP, HostPortPair("myproxy", 70))); |
| 5906 | session_deps_.proxy_resolution_service = |
| 5907 | std::make_unique<ProxyResolutionService>( |
| 5908 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 5909 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 5910 | std::make_unique<CapturingProxyResolverFactory>( |
| 5911 | &capturing_proxy_resolver), |
| 5912 | nullptr); |
| 5913 | |
| 5914 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 5915 | |
| 5916 | const char kMyUrl[] = "https://www.example.org/"; |
| 5917 | spdy::SpdySerializedFrame get(spdy_util_.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 5918 | spdy::SpdySerializedFrame get_resp( |
| 5919 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 5920 | spdy::SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 5921 | |
| 5922 | spdy_util_.UpdateWithStreamDestruction(1); |
| 5923 | spdy::SpdySerializedFrame get2( |
| 5924 | spdy_util_.ConstructSpdyGet(kMyUrl, 3, LOWEST)); |
| 5925 | spdy::SpdySerializedFrame get_resp2( |
| 5926 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 5927 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
| 5928 | |
| 5929 | MockWrite auth_challenge_writes[] = { |
| 5930 | MockWrite(ASYNC, 0, |
| 5931 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5932 | "Host: www.example.org:443\r\n" |
| 5933 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5934 | }; |
| 5935 | |
| 5936 | MockRead auth_challenge_reads[] = { |
| 5937 | MockRead(ASYNC, 1, |
| 5938 | "HTTP/1.1 407 Authentication Required\r\n" |
| 5939 | "Content-Length: 0\r\n" |
| 5940 | "Proxy-Connection: close\r\n" |
| 5941 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
| 5942 | }; |
| 5943 | |
| 5944 | MockWrite spdy_writes[] = { |
| 5945 | MockWrite(ASYNC, 0, |
| 5946 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5947 | "Host: www.example.org:443\r\n" |
| 5948 | "Proxy-Connection: keep-alive\r\n" |
| 5949 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5950 | CreateMockWrite(get, 2), |
| 5951 | CreateMockWrite(get2, 5), |
| 5952 | }; |
| 5953 | |
| 5954 | MockRead spdy_reads[] = { |
| 5955 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n\r\n"), |
| 5956 | CreateMockRead(get_resp, 3, ASYNC), |
| 5957 | CreateMockRead(body, 4, ASYNC), |
| 5958 | CreateMockRead(get_resp2, 6, ASYNC), |
| 5959 | CreateMockRead(body2, 7, ASYNC), |
| 5960 | |
| 5961 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 8), |
| 5962 | }; |
| 5963 | |
| 5964 | SequencedSocketData auth_challenge1(auth_challenge_reads, |
| 5965 | auth_challenge_writes); |
| 5966 | session_deps_.socket_factory->AddSocketDataProvider(&auth_challenge1); |
| 5967 | |
| 5968 | SequencedSocketData auth_challenge2(auth_challenge_reads, |
| 5969 | auth_challenge_writes); |
| 5970 | session_deps_.socket_factory->AddSocketDataProvider(&auth_challenge2); |
| 5971 | |
| 5972 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
| 5973 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5974 | |
| 5975 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 5976 | ssl.next_proto = kProtoHTTP2; |
| 5977 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5978 | |
| 5979 | TestCompletionCallback callback; |
| 5980 | std::string response_data; |
| 5981 | |
| 5982 | // Run first request until an auth challenge is observed. |
| 5983 | HttpRequestInfo request1; |
| 5984 | request1.method = "GET"; |
| 5985 | request1.url = GURL(kMyUrl); |
| 5986 | request1.traffic_annotation = |
| 5987 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5988 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 5989 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 5990 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5991 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 5992 | ASSERT_TRUE(response); |
| 5993 | ASSERT_TRUE(response->headers); |
| 5994 | EXPECT_EQ(407, response->headers->response_code()); |
| 5995 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5996 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 5997 | |
| 5998 | // Run second request until an auth challenge is observed. |
| 5999 | HttpRequestInfo request2; |
| 6000 | request2.method = "GET"; |
| 6001 | request2.url = GURL(kMyUrl); |
| 6002 | request2.traffic_annotation = |
| 6003 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6004 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6005 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
| 6006 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6007 | response = trans2.GetResponseInfo(); |
| 6008 | ASSERT_TRUE(response); |
| 6009 | ASSERT_TRUE(response->headers); |
| 6010 | EXPECT_EQ(407, response->headers->response_code()); |
| 6011 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6012 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 6013 | |
| 6014 | // Now provide credentials for the first request, and wait for it to complete. |
| 6015 | rv = trans1.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 6016 | rv = callback.GetResult(rv); |
| 6017 | EXPECT_THAT(rv, IsOk()); |
| 6018 | response = trans1.GetResponseInfo(); |
| 6019 | ASSERT_TRUE(response); |
| 6020 | ASSERT_TRUE(response->headers); |
| 6021 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6022 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6023 | EXPECT_EQ(kUploadData, response_data); |
| 6024 | |
| 6025 | // Now provide credentials for the second request. It should notice the |
| 6026 | // existing session, and reuse it. |
| 6027 | rv = trans2.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 6028 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6029 | response = trans2.GetResponseInfo(); |
| 6030 | ASSERT_TRUE(response); |
| 6031 | ASSERT_TRUE(response->headers); |
| 6032 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6033 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6034 | EXPECT_EQ(kUploadData, response_data); |
| 6035 | } |
| 6036 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6037 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 6038 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6039 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6040 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 6041 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6042 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6043 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6044 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6045 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6046 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6047 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6048 | |
| 6049 | HttpRequestInfo request1; |
| 6050 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6051 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6052 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6053 | request1.traffic_annotation = |
| 6054 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6055 | |
| 6056 | HttpRequestInfo request2; |
| 6057 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6058 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6059 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6060 | request2.traffic_annotation = |
| 6061 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6062 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6063 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6064 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6065 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6066 | spdy::SpdySerializedFrame conn_resp1( |
| 6067 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6068 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6069 | // Fetch https://www.example.org/ via HTTP. |
| 6070 | const char get1[] = |
| 6071 | "GET / HTTP/1.1\r\n" |
| 6072 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6073 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6074 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6075 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6076 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 6077 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6078 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6079 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6080 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6081 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6082 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6083 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6084 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6085 | // CONNECT to mail.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6086 | spdy::SpdyHeaderBlock connect2_block; |
| 6087 | connect2_block[spdy::kHttp2MethodHeader] = "CONNECT"; |
| 6088 | connect2_block[spdy::kHttp2AuthorityHeader] = "mail.example.org:443"; |
| 6089 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6090 | 3, std::move(connect2_block), LOWEST, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 6091 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6092 | spdy::SpdySerializedFrame conn_resp2( |
| 6093 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6094 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6095 | // Fetch https://mail.example.org/ via HTTP. |
| 6096 | const char get2[] = |
| 6097 | "GET / HTTP/1.1\r\n" |
| 6098 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6099 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6100 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6101 | spdy_util_.ConstructSpdyDataFrame(3, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6102 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 6103 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6104 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6105 | spdy_util_.ConstructSpdyDataFrame(3, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6106 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6107 | spdy_util_.ConstructSpdyDataFrame(3, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6108 | |
| 6109 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6110 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 6111 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6112 | }; |
| 6113 | |
| 6114 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6115 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 6116 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 6117 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 6118 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 6119 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 6120 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 6121 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6122 | }; |
| 6123 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6124 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6125 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6126 | |
| 6127 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6128 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6129 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6130 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6131 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6132 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6133 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6134 | |
| 6135 | TestCompletionCallback callback; |
| 6136 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6137 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6138 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6139 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6140 | |
| 6141 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6142 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6143 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6144 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6145 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6146 | ASSERT_TRUE(response); |
| 6147 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6148 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6149 | |
| 6150 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6151 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6152 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6153 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6154 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6155 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6156 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6157 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6158 | |
| 6159 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6160 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6161 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 6162 | // to be created, so the socket's load timing looks like a fresh connection. |
| 6163 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6164 | |
| 6165 | // The requests should have different IDs, since they each are using their own |
| 6166 | // separate stream. |
| 6167 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6168 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6169 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6170 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6171 | } |
| 6172 | |
| 6173 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 6174 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6175 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6176 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 6177 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6178 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6179 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6180 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6181 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6182 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6183 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6184 | |
| 6185 | HttpRequestInfo request1; |
| 6186 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6187 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6188 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6189 | request1.traffic_annotation = |
| 6190 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6191 | |
| 6192 | HttpRequestInfo request2; |
| 6193 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6194 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6195 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6196 | request2.traffic_annotation = |
| 6197 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6198 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6199 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6200 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6201 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6202 | spdy::SpdySerializedFrame conn_resp1( |
| 6203 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6204 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6205 | // Fetch https://www.example.org/ via HTTP. |
| 6206 | const char get1[] = |
| 6207 | "GET / HTTP/1.1\r\n" |
| 6208 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6209 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6210 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6211 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6212 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 6213 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6214 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6215 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6216 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6217 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6218 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6219 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6220 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6221 | // Fetch https://www.example.org/2 via HTTP. |
| 6222 | const char get2[] = |
| 6223 | "GET /2 HTTP/1.1\r\n" |
| 6224 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6225 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6226 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6227 | spdy_util_.ConstructSpdyDataFrame(1, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6228 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 6229 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6230 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6231 | spdy_util_.ConstructSpdyDataFrame(1, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6232 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6233 | spdy_util_.ConstructSpdyDataFrame(1, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6234 | |
| 6235 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6236 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 6237 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6238 | }; |
| 6239 | |
| 6240 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6241 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 6242 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 6243 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6244 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 6245 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6246 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6247 | }; |
| 6248 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6249 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6250 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6251 | |
| 6252 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6253 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6254 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6255 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6256 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6257 | |
| 6258 | TestCompletionCallback callback; |
| 6259 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6260 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6261 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6262 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6263 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6264 | |
| 6265 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6266 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6267 | |
| 6268 | LoadTimingInfo load_timing_info; |
| 6269 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6270 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6271 | |
| 6272 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6273 | ASSERT_TRUE(response); |
| 6274 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6275 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6276 | |
| 6277 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6278 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6279 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6280 | trans.reset(); |
| 6281 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6282 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6283 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6284 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6285 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6286 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6287 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6288 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6289 | |
| 6290 | LoadTimingInfo load_timing_info2; |
| 6291 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 6292 | TestLoadTimingReused(load_timing_info2); |
| 6293 | |
| 6294 | // The requests should have the same ID. |
| 6295 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6296 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6297 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6298 | } |
| 6299 | |
| 6300 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 6301 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6302 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6303 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6304 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6305 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6306 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6307 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6308 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6309 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6310 | |
| 6311 | HttpRequestInfo request1; |
| 6312 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6313 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6314 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6315 | request1.traffic_annotation = |
| 6316 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6317 | |
| 6318 | HttpRequestInfo request2; |
| 6319 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6320 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6321 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6322 | request2.traffic_annotation = |
| 6323 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6324 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6325 | // http://www.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6326 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6327 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6328 | spdy::SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6329 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6330 | spdy::SpdySerializedFrame get_resp1( |
| 6331 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 6332 | spdy::SpdySerializedFrame body1( |
| 6333 | spdy_util_.ConstructSpdyDataFrame(1, "1", true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 6334 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6335 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6336 | // http://mail.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6337 | spdy::SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6338 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6339 | spdy::SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6340 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6341 | spdy::SpdySerializedFrame get_resp2( |
| 6342 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 6343 | spdy::SpdySerializedFrame body2( |
| 6344 | spdy_util_.ConstructSpdyDataFrame(3, "22", true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6345 | |
| 6346 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6347 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6348 | }; |
| 6349 | |
| 6350 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6351 | CreateMockRead(get_resp1, 1, ASYNC), |
| 6352 | CreateMockRead(body1, 2, ASYNC), |
| 6353 | CreateMockRead(get_resp2, 4, ASYNC), |
| 6354 | CreateMockRead(body2, 5, ASYNC), |
| 6355 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6356 | }; |
| 6357 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6358 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6359 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6360 | |
| 6361 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6362 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6363 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6364 | |
| 6365 | TestCompletionCallback callback; |
| 6366 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6367 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6368 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6369 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6370 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6371 | |
| 6372 | LoadTimingInfo load_timing_info; |
| 6373 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6374 | TestLoadTimingNotReused(load_timing_info, |
| 6375 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6376 | |
| 6377 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6378 | ASSERT_TRUE(response); |
| 6379 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 6380 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6381 | |
| 6382 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6383 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6384 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 6385 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6386 | // Delete the first request, so the second one can reuse the socket. |
| 6387 | trans.reset(); |
| 6388 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6389 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6390 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6391 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6392 | |
| 6393 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6394 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6395 | TestLoadTimingReused(load_timing_info2); |
| 6396 | |
| 6397 | // The requests should have the same ID. |
| 6398 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6399 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6400 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6401 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6402 | } |
| 6403 | |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6404 | // Test that an HTTP/2 CONNECT through an HTTPS Proxy to a HTTP/2 server and a |
| 6405 | // direct (non-proxied) request to the proxy server are not pooled, as that |
| 6406 | // would break socket pool isolation. |
| 6407 | TEST_F(HttpNetworkTransactionTest, SpdyProxyIsolation1) { |
| 6408 | ProxyConfig proxy_config; |
| 6409 | proxy_config.set_auto_detect(true); |
| 6410 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 6411 | |
| 6412 | CapturingProxyResolver capturing_proxy_resolver; |
| 6413 | session_deps_.proxy_resolution_service = |
| 6414 | std::make_unique<ProxyResolutionService>( |
| 6415 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 6416 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 6417 | std::make_unique<CapturingProxyResolverFactory>( |
| 6418 | &capturing_proxy_resolver), |
| 6419 | nullptr); |
| 6420 | |
| 6421 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6422 | |
| 6423 | SpdyTestUtil spdy_util1; |
| 6424 | // CONNECT to www.example.org:443 via HTTP/2. |
| 6425 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
| 6426 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 6427 | // fetch https://www.example.org/ via HTTP/2. |
| 6428 | const char kMyUrl[] = "https://www.example.org/"; |
| 6429 | spdy::SpdySerializedFrame get(spdy_util1.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 6430 | spdy::SpdySerializedFrame wrapped_get( |
| 6431 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 6432 | spdy::SpdySerializedFrame conn_resp( |
| 6433 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 6434 | spdy::SpdySerializedFrame get_resp( |
| 6435 | spdy_util1.ConstructSpdyGetReply(NULL, 0, 1)); |
| 6436 | spdy::SpdySerializedFrame wrapped_get_resp( |
| 6437 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 6438 | spdy::SpdySerializedFrame body(spdy_util1.ConstructSpdyDataFrame(1, true)); |
| 6439 | spdy::SpdySerializedFrame wrapped_body( |
| 6440 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
| 6441 | spdy::SpdySerializedFrame window_update_get_resp( |
| 6442 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 6443 | spdy::SpdySerializedFrame window_update_body( |
| 6444 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
| 6445 | |
| 6446 | MockWrite spdy_writes1[] = { |
| 6447 | CreateMockWrite(connect, 0), |
| 6448 | CreateMockWrite(wrapped_get, 2), |
| 6449 | CreateMockWrite(window_update_get_resp, 6), |
| 6450 | CreateMockWrite(window_update_body, 7), |
| 6451 | }; |
| 6452 | |
| 6453 | MockRead spdy_reads1[] = { |
| 6454 | CreateMockRead(conn_resp, 1, ASYNC), |
| 6455 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 6456 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 6457 | CreateMockRead(wrapped_body, 5, ASYNC), |
| 6458 | MockRead(ASYNC, 0, 8), |
| 6459 | }; |
| 6460 | |
| 6461 | SequencedSocketData spdy_data1(spdy_reads1, spdy_writes1); |
| 6462 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data1); |
| 6463 | |
| 6464 | // Fetch https://proxy:70/ via HTTP/2. Needs a new SpdyTestUtil, since it uses |
| 6465 | // a new pipe. |
| 6466 | SpdyTestUtil spdy_util2; |
| 6467 | spdy::SpdySerializedFrame req( |
| 6468 | spdy_util2.ConstructSpdyGet("https://proxy:70/", 1, LOWEST)); |
| 6469 | MockWrite spdy_writes2[] = {CreateMockWrite(req, 0)}; |
| 6470 | |
| 6471 | spdy::SpdySerializedFrame resp( |
| 6472 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6473 | spdy::SpdySerializedFrame data(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 6474 | MockRead spdy_reads2[] = { |
| 6475 | CreateMockRead(resp, 1), |
| 6476 | CreateMockRead(data, 2), |
| 6477 | MockRead(ASYNC, 0, 3), |
| 6478 | }; |
| 6479 | SequencedSocketData spdy_data2(spdy_reads2, spdy_writes2); |
| 6480 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data2); |
| 6481 | |
| 6482 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6483 | ssl.next_proto = kProtoHTTP2; |
| 6484 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6485 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6486 | ssl2.next_proto = kProtoHTTP2; |
| 6487 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6488 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6489 | ssl3.next_proto = kProtoHTTP2; |
| 6490 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6491 | |
| 6492 | TestCompletionCallback callback; |
| 6493 | std::string response_data; |
| 6494 | |
| 6495 | // Make a request using proxy:70 as a HTTP/2 proxy. |
| 6496 | capturing_proxy_resolver.set_proxy_server( |
| 6497 | ProxyServer(ProxyServer::SCHEME_HTTPS, HostPortPair("proxy", 70))); |
| 6498 | HttpRequestInfo request1; |
| 6499 | request1.method = "GET"; |
| 6500 | request1.url = GURL("https://www.example.org/"); |
| 6501 | request1.traffic_annotation = |
| 6502 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6503 | |
| 6504 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 6505 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 6506 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6507 | |
| 6508 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 6509 | base::RunLoop().RunUntilIdle(); |
| 6510 | // Now allow the read of the response to complete. |
| 6511 | spdy_data1.Resume(); |
| 6512 | rv = callback.WaitForResult(); |
| 6513 | EXPECT_THAT(rv, IsOk()); |
| 6514 | |
| 6515 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 6516 | ASSERT_TRUE(response); |
| 6517 | ASSERT_TRUE(response->headers); |
| 6518 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6519 | |
| 6520 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6521 | EXPECT_EQ(kUploadData, response_data); |
| 6522 | RunUntilIdle(); |
| 6523 | |
| 6524 | // Make a direct HTTP/2 request to proxy:70. |
| 6525 | capturing_proxy_resolver.set_proxy_server(ProxyServer::Direct()); |
| 6526 | HttpRequestInfo request2; |
| 6527 | request2.method = "GET"; |
| 6528 | request2.url = GURL("https://proxy:70/"); |
| 6529 | request2.traffic_annotation = |
| 6530 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6531 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6532 | EXPECT_THAT(callback.GetResult(trans2.Start(&request2, callback.callback(), |
| 6533 | NetLogWithSource())), |
| 6534 | IsOk()); |
| 6535 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6536 | } |
| 6537 | |
| 6538 | // Same as above, but reverse request order, since the code to check for an |
| 6539 | // existing session is different for tunnels and direct connections. |
| 6540 | TEST_F(HttpNetworkTransactionTest, SpdyProxyIsolation2) { |
| 6541 | // Configure against https proxy server "myproxy:80". |
| 6542 | ProxyConfig proxy_config; |
| 6543 | proxy_config.set_auto_detect(true); |
| 6544 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 6545 | |
| 6546 | CapturingProxyResolver capturing_proxy_resolver; |
| 6547 | session_deps_.proxy_resolution_service = |
| 6548 | std::make_unique<ProxyResolutionService>( |
| 6549 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 6550 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 6551 | std::make_unique<CapturingProxyResolverFactory>( |
| 6552 | &capturing_proxy_resolver), |
| 6553 | nullptr); |
| 6554 | |
| 6555 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6556 | // Fetch https://proxy:70/ via HTTP/2. |
| 6557 | SpdyTestUtil spdy_util1; |
| 6558 | spdy::SpdySerializedFrame req( |
| 6559 | spdy_util1.ConstructSpdyGet("https://proxy:70/", 1, LOWEST)); |
| 6560 | MockWrite spdy_writes1[] = {CreateMockWrite(req, 0)}; |
| 6561 | |
| 6562 | spdy::SpdySerializedFrame resp( |
| 6563 | spdy_util1.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6564 | spdy::SpdySerializedFrame data(spdy_util1.ConstructSpdyDataFrame(1, true)); |
| 6565 | MockRead spdy_reads1[] = { |
| 6566 | CreateMockRead(resp, 1), |
| 6567 | CreateMockRead(data, 2), |
| 6568 | MockRead(ASYNC, 0, 3), |
| 6569 | }; |
| 6570 | SequencedSocketData spdy_data1(spdy_reads1, spdy_writes1); |
| 6571 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data1); |
| 6572 | |
| 6573 | SpdyTestUtil spdy_util2; |
| 6574 | // CONNECT to www.example.org:443 via HTTP/2. |
| 6575 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
| 6576 | nullptr, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 6577 | // fetch https://www.example.org/ via HTTP/2. |
| 6578 | const char kMyUrl[] = "https://www.example.org/"; |
| 6579 | spdy::SpdySerializedFrame get(spdy_util2.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 6580 | spdy::SpdySerializedFrame wrapped_get( |
| 6581 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 6582 | spdy::SpdySerializedFrame conn_resp( |
| 6583 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6584 | spdy::SpdySerializedFrame get_resp( |
| 6585 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6586 | spdy::SpdySerializedFrame wrapped_get_resp( |
| 6587 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 6588 | spdy::SpdySerializedFrame body(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 6589 | spdy::SpdySerializedFrame wrapped_body( |
| 6590 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
| 6591 | spdy::SpdySerializedFrame window_update_get_resp( |
| 6592 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 6593 | spdy::SpdySerializedFrame window_update_body( |
| 6594 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
| 6595 | |
| 6596 | MockWrite spdy_writes2[] = { |
| 6597 | CreateMockWrite(connect, 0), |
| 6598 | CreateMockWrite(wrapped_get, 2), |
| 6599 | CreateMockWrite(window_update_get_resp, 6), |
| 6600 | CreateMockWrite(window_update_body, 7), |
| 6601 | }; |
| 6602 | |
| 6603 | MockRead spdy_reads2[] = { |
| 6604 | CreateMockRead(conn_resp, 1, ASYNC), |
| 6605 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 6606 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 6607 | CreateMockRead(wrapped_body, 5, ASYNC), |
| 6608 | MockRead(ASYNC, 0, 8), |
| 6609 | }; |
| 6610 | |
| 6611 | SequencedSocketData spdy_data2(spdy_reads2, spdy_writes2); |
| 6612 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data2); |
| 6613 | |
| 6614 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6615 | ssl.next_proto = kProtoHTTP2; |
| 6616 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6617 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6618 | ssl2.next_proto = kProtoHTTP2; |
| 6619 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6620 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6621 | ssl3.next_proto = kProtoHTTP2; |
| 6622 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6623 | |
| 6624 | TestCompletionCallback callback; |
| 6625 | std::string response_data; |
| 6626 | |
| 6627 | // Make a direct HTTP/2 request to proxy:70. |
| 6628 | capturing_proxy_resolver.set_proxy_server(ProxyServer::Direct()); |
| 6629 | HttpRequestInfo request1; |
| 6630 | request1.method = "GET"; |
| 6631 | request1.url = GURL("https://proxy:70/"); |
| 6632 | request1.traffic_annotation = |
| 6633 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6634 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 6635 | EXPECT_THAT(callback.GetResult(trans1.Start(&request1, callback.callback(), |
| 6636 | NetLogWithSource())), |
| 6637 | IsOk()); |
| 6638 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6639 | RunUntilIdle(); |
| 6640 | |
| 6641 | // Make a request using proxy:70 as a HTTP/2 proxy. |
| 6642 | capturing_proxy_resolver.set_proxy_server( |
| 6643 | ProxyServer(ProxyServer::SCHEME_HTTPS, HostPortPair("proxy", 70))); |
| 6644 | HttpRequestInfo request2; |
| 6645 | request2.method = "GET"; |
| 6646 | request2.url = GURL("https://www.example.org/"); |
| 6647 | request2.traffic_annotation = |
| 6648 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6649 | |
| 6650 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6651 | int rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
| 6652 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6653 | |
| 6654 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 6655 | base::RunLoop().RunUntilIdle(); |
| 6656 | // Now allow the read of the response to complete. |
| 6657 | spdy_data2.Resume(); |
| 6658 | rv = callback.WaitForResult(); |
| 6659 | EXPECT_THAT(rv, IsOk()); |
| 6660 | |
| 6661 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
| 6662 | ASSERT_TRUE(response2); |
| 6663 | ASSERT_TRUE(response2->headers); |
| 6664 | EXPECT_EQ("HTTP/1.1 200", response2->headers->GetStatusLine()); |
| 6665 | |
| 6666 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6667 | EXPECT_EQ(kUploadData, response_data); |
| 6668 | } |
| 6669 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6670 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6671 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6672 | HttpRequestInfo request; |
| 6673 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6674 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6675 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 6676 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6677 | request.traffic_annotation = |
| 6678 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6679 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6680 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6681 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6682 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6683 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6684 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6685 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6686 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6687 | // Since we have proxy, should use full url |
| 6688 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6689 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 6690 | "Host: www.example.org\r\n" |
| 6691 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6692 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6693 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6694 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6695 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 6696 | "Host: www.example.org\r\n" |
| 6697 | "Proxy-Connection: keep-alive\r\n" |
| 6698 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6699 | }; |
| 6700 | |
| 6701 | // The proxy responds to the GET with a 407, using a persistent |
| 6702 | // connection. |
| 6703 | MockRead data_reads1[] = { |
| 6704 | // No credentials. |
| 6705 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 6706 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6707 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 6708 | MockRead("Content-Length: 0\r\n\r\n"), |
| 6709 | |
| 6710 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6711 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6712 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6713 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6714 | }; |
| 6715 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6716 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6717 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6718 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6719 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6720 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6721 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6722 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6723 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6724 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6725 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6726 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6727 | |
| 6728 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6729 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6730 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6731 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6732 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6733 | TestLoadTimingNotReused(load_timing_info, |
| 6734 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6735 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6736 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6737 | ASSERT_TRUE(response); |
| 6738 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6739 | EXPECT_EQ(407, response->headers->response_code()); |
| 6740 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 6741 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6742 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6743 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6744 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6745 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6746 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6747 | |
| 6748 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6749 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6750 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6751 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6752 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6753 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 6754 | TestLoadTimingReused(load_timing_info); |
| 6755 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6756 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6757 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6758 | |
| 6759 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6760 | EXPECT_EQ(200, response->headers->response_code()); |
| 6761 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6762 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6763 | |
| 6764 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6765 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6766 | } |
| 6767 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6768 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6769 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6770 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6771 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6772 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6773 | request.traffic_annotation = |
| 6774 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6775 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6776 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6777 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6778 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6779 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6780 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6781 | // Since we have proxy, should try to establish tunnel. |
| 6782 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6783 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6784 | "Host: www.example.org:443\r\n" |
| 6785 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6786 | }; |
| 6787 | |
| 6788 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6789 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 6790 | // No response body because the test stops reading here. |
| 6791 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6792 | }; |
| 6793 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6794 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6795 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6796 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6797 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6798 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6799 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6800 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6801 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6802 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6803 | |
| 6804 | rv = callback.WaitForResult(); |
| 6805 | EXPECT_EQ(expected_status, rv); |
| 6806 | } |
| 6807 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6808 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 6809 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6810 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6811 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6812 | } |
| 6813 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6814 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6815 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 6816 | } |
| 6817 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6818 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6819 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 6820 | } |
| 6821 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6822 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6823 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 6824 | } |
| 6825 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6826 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6827 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 6828 | } |
| 6829 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6830 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6831 | ConnectStatusHelper( |
| 6832 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 6833 | } |
| 6834 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6835 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6836 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 6837 | } |
| 6838 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6839 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6840 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 6841 | } |
| 6842 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6843 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6844 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 6845 | } |
| 6846 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6847 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6848 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 6849 | } |
| 6850 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6851 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6852 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 6853 | } |
| 6854 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6855 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6856 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 6857 | } |
| 6858 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6859 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6860 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 6861 | } |
| 6862 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6863 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6864 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 6865 | } |
| 6866 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6867 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6868 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 6869 | } |
| 6870 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6871 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6872 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 6873 | } |
| 6874 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6875 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6876 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 6877 | } |
| 6878 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6879 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 6880 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 6881 | } |
| 6882 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6883 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6884 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 6885 | } |
| 6886 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6887 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6888 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 6889 | } |
| 6890 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6891 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6892 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 6893 | } |
| 6894 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6895 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6896 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 6897 | } |
| 6898 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6899 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6900 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 6901 | } |
| 6902 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6903 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6904 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 6905 | } |
| 6906 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6907 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6908 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 6909 | } |
| 6910 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6911 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6912 | ConnectStatusHelperWithExpectedStatus( |
| 6913 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 6914 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6915 | } |
| 6916 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6917 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6918 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 6919 | } |
| 6920 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6921 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6922 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 6923 | } |
| 6924 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6925 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6926 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 6927 | } |
| 6928 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6929 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6930 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 6931 | } |
| 6932 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6933 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6934 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 6935 | } |
| 6936 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6937 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6938 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 6939 | } |
| 6940 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6941 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6942 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 6943 | } |
| 6944 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6945 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6946 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 6947 | } |
| 6948 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6949 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6950 | ConnectStatusHelper( |
| 6951 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 6952 | } |
| 6953 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6954 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6955 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 6956 | } |
| 6957 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6958 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6959 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 6960 | } |
| 6961 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6962 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6963 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 6964 | } |
| 6965 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6966 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6967 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 6968 | } |
| 6969 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6970 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6971 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 6972 | } |
| 6973 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6974 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6975 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 6976 | } |
| 6977 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6978 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6979 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 6980 | } |
| 6981 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6982 | // Test the flow when both the proxy server AND origin server require |
| 6983 | // authentication. Again, this uses basic auth for both since that is |
| 6984 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6985 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6986 | HttpRequestInfo request; |
| 6987 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6988 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6989 | request.traffic_annotation = |
| 6990 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6991 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6992 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6993 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6994 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6995 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6996 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6997 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6998 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6999 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7000 | MockWrite( |
| 7001 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7002 | "Host: www.example.org\r\n" |
| 7003 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7004 | }; |
| 7005 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7006 | MockRead data_reads1[] = { |
| 7007 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 7008 | // Give a couple authenticate options (only the middle one is actually |
| 7009 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 7010 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7011 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7012 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 7013 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7014 | // Large content-length -- won't matter, as connection will be reset. |
| 7015 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7016 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7017 | }; |
| 7018 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7019 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7020 | // request we should be issuing -- the final header line contains the |
| 7021 | // proxy's credentials. |
| 7022 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7023 | MockWrite( |
| 7024 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7025 | "Host: www.example.org\r\n" |
| 7026 | "Proxy-Connection: keep-alive\r\n" |
| 7027 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7028 | }; |
| 7029 | |
| 7030 | // Now the proxy server lets the request pass through to origin server. |
| 7031 | // The origin server responds with a 401. |
| 7032 | MockRead data_reads2[] = { |
| 7033 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7034 | // Note: We are using the same realm-name as the proxy server. This is |
| 7035 | // completely valid, as realms are unique across hosts. |
| 7036 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7037 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7038 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7039 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7040 | }; |
| 7041 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7042 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7043 | // the credentials for both the proxy and origin server. |
| 7044 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7045 | MockWrite( |
| 7046 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7047 | "Host: www.example.org\r\n" |
| 7048 | "Proxy-Connection: keep-alive\r\n" |
| 7049 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 7050 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7051 | }; |
| 7052 | |
| 7053 | // Lastly we get the desired content. |
| 7054 | MockRead data_reads3[] = { |
| 7055 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7056 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7057 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7058 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7059 | }; |
| 7060 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7061 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7062 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 7063 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7064 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7065 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7066 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7067 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7068 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7069 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7070 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7071 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7072 | |
| 7073 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7074 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7075 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7076 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7077 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7078 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7079 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7080 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7081 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7082 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7083 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7084 | |
| 7085 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7086 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7087 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7088 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7089 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7090 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7091 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7092 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7093 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7094 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 7095 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7096 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7097 | |
| 7098 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7099 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7100 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7101 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7102 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7103 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7104 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7105 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7106 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 7107 | // can't hook into its internals to cause it to generate predictable NTLM |
| 7108 | // authorization headers. |
| 7109 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7110 | // The NTLM authentication unit tests are based on known test data from the |
| 7111 | // [MS-NLMP] Specification [1]. These tests are primarily of the authentication |
| 7112 | // flow rather than the implementation of the NTLM protocol. See net/ntlm |
| 7113 | // for the implementation and testing of the protocol. |
| 7114 | // |
| 7115 | // [1] https://msdn.microsoft.com/en-us/library/cc236621.aspx |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7116 | |
| 7117 | // Enter the correct password and authenticate successfully. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7118 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7119 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7120 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7121 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7122 | request.traffic_annotation = |
| 7123 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7124 | |
| 7125 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 7126 | // to other auth schemes. |
| 7127 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7128 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7129 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7130 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7131 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7132 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7133 | // Generate the NTLM messages based on known test data. |
| 7134 | std::string negotiate_msg; |
| 7135 | std::string challenge_msg; |
| 7136 | std::string authenticate_msg; |
| 7137 | base::Base64Encode( |
| 7138 | base::StringPiece( |
| 7139 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7140 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7141 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7142 | base::Base64Encode( |
| 7143 | base::StringPiece( |
| 7144 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7145 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7146 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7147 | base::Base64Encode( |
| 7148 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7149 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7150 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7151 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7152 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7153 | &authenticate_msg); |
| 7154 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7155 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7156 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 7157 | "Host: server\r\n" |
| 7158 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7159 | }; |
| 7160 | |
| 7161 | MockRead data_reads1[] = { |
| 7162 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 7163 | // Negotiate and NTLM are often requested together. However, we only want |
| 7164 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 7165 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7166 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 7167 | MockRead("Connection: close\r\n"), |
| 7168 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 7169 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7170 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7171 | }; |
| 7172 | |
| 7173 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7174 | // After restarting with a null identity, this is the |
| 7175 | // request we should be issuing -- the final header line contains a Type |
| 7176 | // 1 message. |
| 7177 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7178 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7179 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7180 | "Authorization: NTLM "), |
| 7181 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7182 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7183 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7184 | // (using correct credentials). The second request continues on the |
| 7185 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7186 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7187 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7188 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7189 | "Authorization: NTLM "), |
| 7190 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7191 | }; |
| 7192 | |
| 7193 | MockRead data_reads2[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7194 | // The origin server responds with a Type 2 message. |
| 7195 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7196 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7197 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7198 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7199 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7200 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7201 | // Lastly we get the desired content. |
| 7202 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7203 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 7204 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7205 | }; |
| 7206 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7207 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7208 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7209 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7210 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7211 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7212 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7213 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7214 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 7215 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 7216 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7217 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7218 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7219 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7220 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7221 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7222 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7223 | |
| 7224 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7225 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7226 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7227 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7228 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7229 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7230 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7231 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7232 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7233 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7234 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7235 | rv = trans.RestartWithAuth( |
| 7236 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7237 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7238 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7239 | |
| 7240 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7241 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7242 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7243 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7244 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7245 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7246 | ASSERT_TRUE(response); |
| 7247 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7248 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7249 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7250 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7251 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7252 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7253 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7254 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7255 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7256 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7257 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7258 | ASSERT_TRUE(response); |
| 7259 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7260 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7261 | |
| 7262 | std::string response_data; |
| 7263 | rv = ReadTransaction(&trans, &response_data); |
| 7264 | EXPECT_THAT(rv, IsOk()); |
| 7265 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7266 | |
| 7267 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7268 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 7269 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 7270 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7271 | } |
| 7272 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7273 | // Enter a wrong password, and then the correct one. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7274 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2WrongThenRightPassword) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7275 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7276 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7277 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7278 | request.traffic_annotation = |
| 7279 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7280 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7281 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7282 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7283 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7284 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7285 | // Generate the NTLM messages based on known test data. |
| 7286 | std::string negotiate_msg; |
| 7287 | std::string challenge_msg; |
| 7288 | std::string authenticate_msg; |
| 7289 | base::Base64Encode( |
| 7290 | base::StringPiece( |
| 7291 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7292 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7293 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7294 | base::Base64Encode( |
| 7295 | base::StringPiece( |
| 7296 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7297 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7298 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7299 | base::Base64Encode( |
| 7300 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7301 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7302 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7303 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7304 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7305 | &authenticate_msg); |
| 7306 | |
| 7307 | // The authenticate message when |kWrongPassword| is sent. |
| 7308 | std::string wrong_password_authenticate_msg( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7309 | "TlRMTVNTUAADAAAAGAAYAFgAAACKAIoAcAAAAAwADAD6AAAACAAIAAYBAAAQABAADgEAAAAA" |
| 7310 | "AABYAAAAA4IIAAAAAAAAAAAAAPknEYqtJQtusopDRSfYzAAAAAAAAAAAAAAAAAAAAAAAAAAA" |
| 7311 | "AAAAAOtVz38osnFdRRggUQHUJ3EBAQAAAAAAAIALyP0A1NIBqqqqqqqqqqoAAAAAAgAMAEQA" |
| 7312 | "bwBtAGEAaQBuAAEADABTAGUAcgB2AGUAcgAGAAQAAgAAAAoAEAAAAAAAAAAAAAAAAAAAAAAA" |
| 7313 | "CQAWAEgAVABUAFAALwBzAGUAcgB2AGUAcgAAAAAAAAAAAEQAbwBtAGEAaQBuAFUAcwBlAHIA" |
| 7314 | "QwBPAE0AUABVAFQARQBSAA=="); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7315 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7316 | // Sanity check that it's the same length as the correct authenticate message |
| 7317 | // and that it's different. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7318 | ASSERT_EQ(authenticate_msg.length(), |
| 7319 | wrong_password_authenticate_msg.length()); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7320 | ASSERT_NE(authenticate_msg, wrong_password_authenticate_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7321 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7322 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7323 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 7324 | "Host: server\r\n" |
| 7325 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7326 | }; |
| 7327 | |
| 7328 | MockRead data_reads1[] = { |
| 7329 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 7330 | // Negotiate and NTLM are often requested together. However, we only want |
| 7331 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 7332 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7333 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 7334 | MockRead("Connection: close\r\n"), |
| 7335 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 7336 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7337 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7338 | }; |
| 7339 | |
| 7340 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7341 | // After restarting with a null identity, this is the |
| 7342 | // request we should be issuing -- the final header line contains a Type |
| 7343 | // 1 message. |
| 7344 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7345 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7346 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7347 | "Authorization: NTLM "), |
| 7348 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7349 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7350 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7351 | // (using incorrect credentials). The second request continues on the |
| 7352 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7353 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7354 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7355 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7356 | "Authorization: NTLM "), |
| 7357 | MockWrite(wrong_password_authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7358 | }; |
| 7359 | |
| 7360 | MockRead data_reads2[] = { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7361 | // The origin server responds with a Type 2 message. |
| 7362 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 7363 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7364 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
| 7365 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7366 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7367 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7368 | // Wrong password. |
| 7369 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 7370 | MockRead("WWW-Authenticate: NTLM\r\n"), MockRead("Connection: close\r\n"), |
| 7371 | MockRead("Content-Length: 42\r\n"), |
| 7372 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7373 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7374 | }; |
| 7375 | |
| 7376 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7377 | // After restarting with a null identity, this is the |
| 7378 | // request we should be issuing -- the final header line contains a Type |
| 7379 | // 1 message. |
| 7380 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7381 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7382 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7383 | "Authorization: NTLM "), |
| 7384 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7385 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7386 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 7387 | // (the credentials for the origin server). The second request continues |
| 7388 | // on the same connection. |
| 7389 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7390 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7391 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7392 | "Authorization: NTLM "), |
| 7393 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7394 | }; |
| 7395 | |
| 7396 | MockRead data_reads3[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7397 | // The origin server responds with a Type 2 message. |
| 7398 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7399 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7400 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7401 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7402 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7403 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7404 | // Lastly we get the desired content. |
| 7405 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7406 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 7407 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7408 | }; |
| 7409 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7410 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7411 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 7412 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7413 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7414 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7415 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7416 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7417 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7418 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7419 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 7420 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 7421 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 7422 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 7423 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7424 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7425 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7426 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7427 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7428 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7429 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7430 | |
| 7431 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7432 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7433 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7434 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7435 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7436 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7437 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7438 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7439 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7440 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7441 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7442 | // Enter the wrong password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7443 | rv = trans.RestartWithAuth( |
| 7444 | AuthCredentials(ntlm::test::kDomainUserCombined, kWrongPassword), |
| 7445 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7446 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7447 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7448 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7449 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7450 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7451 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7452 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7453 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7454 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7455 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7456 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7457 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7458 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7459 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7460 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7461 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7462 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7463 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7464 | |
| 7465 | // Now enter the right password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7466 | rv = trans.RestartWithAuth( |
| 7467 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7468 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7469 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7470 | |
| 7471 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7472 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7473 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7474 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7475 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7476 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7477 | |
| 7478 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7479 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7480 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7481 | |
| 7482 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7483 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7484 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7485 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7486 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7487 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7488 | |
| 7489 | std::string response_data; |
| 7490 | rv = ReadTransaction(&trans, &response_data); |
| 7491 | EXPECT_THAT(rv, IsOk()); |
| 7492 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7493 | |
| 7494 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7495 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 7496 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 7497 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
| 7498 | EXPECT_TRUE(data3.AllReadDataConsumed()); |
| 7499 | EXPECT_TRUE(data3.AllWriteDataConsumed()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7500 | } |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7501 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 7502 | // Server requests NTLM authentication, which is not supported over HTTP/2. |
| 7503 | // Subsequent request with authorization header should be sent over HTTP/1.1. |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7504 | TEST_F(HttpNetworkTransactionTest, NTLMOverHttp2) { |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7505 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7506 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7507 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7508 | const char* kUrl = "https://server/kids/login.aspx"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7509 | |
| 7510 | HttpRequestInfo request; |
| 7511 | request.method = "GET"; |
| 7512 | request.url = GURL(kUrl); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7513 | request.traffic_annotation = |
| 7514 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7515 | |
| 7516 | // First request without credentials. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7517 | spdy::SpdyHeaderBlock request_headers0( |
| 7518 | spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 7519 | spdy::SpdySerializedFrame request0(spdy_util_.ConstructSpdyHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7520 | 1, std::move(request_headers0), LOWEST, true)); |
| 7521 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7522 | spdy::SpdyHeaderBlock response_headers0; |
| 7523 | response_headers0[spdy::kHttp2StatusHeader] = "401"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7524 | response_headers0["www-authenticate"] = "NTLM"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7525 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyResponseHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7526 | 1, std::move(response_headers0), true)); |
| 7527 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7528 | // Stream 1 is closed. |
| 7529 | spdy_util_.UpdateWithStreamDestruction(1); |
| 7530 | |
| 7531 | // Generate the NTLM messages based on known test data. |
| 7532 | std::string negotiate_msg; |
| 7533 | std::string challenge_msg; |
| 7534 | std::string authenticate_msg; |
| 7535 | base::Base64Encode( |
| 7536 | base::StringPiece( |
| 7537 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7538 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7539 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7540 | base::Base64Encode( |
| 7541 | base::StringPiece( |
| 7542 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7543 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7544 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7545 | base::Base64Encode( |
| 7546 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7547 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7548 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7549 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7550 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7551 | &authenticate_msg); |
| 7552 | |
| 7553 | // Retry with authorization header. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7554 | spdy::SpdyHeaderBlock request_headers1( |
| 7555 | spdy_util_.ConstructGetHeaderBlock(kUrl)); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7556 | request_headers1["authorization"] = std::string("NTLM ") + negotiate_msg; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7557 | spdy::SpdySerializedFrame request1(spdy_util_.ConstructSpdyHeaders( |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7558 | 3, std::move(request_headers1), LOWEST, true)); |
| 7559 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7560 | spdy::SpdySerializedFrame rst( |
| 7561 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_HTTP_1_1_REQUIRED)); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7562 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 7563 | MockWrite writes0[] = {CreateMockWrite(request0, 0)}; |
| 7564 | MockRead reads0[] = {CreateMockRead(resp, 1), MockRead(ASYNC, 0, 2)}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7565 | |
| 7566 | // Retry yet again using HTTP/1.1. |
| 7567 | MockWrite writes1[] = { |
| 7568 | // After restarting with a null identity, this is the |
| 7569 | // request we should be issuing -- the final header line contains a Type |
| 7570 | // 1 message. |
| 7571 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7572 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7573 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7574 | "Authorization: NTLM "), |
| 7575 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7576 | |
| 7577 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 7578 | // (the credentials for the origin server). The second request continues |
| 7579 | // on the same connection. |
| 7580 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7581 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7582 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7583 | "Authorization: NTLM "), |
| 7584 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7585 | }; |
| 7586 | |
| 7587 | MockRead reads1[] = { |
| 7588 | // The origin server responds with a Type 2 message. |
| 7589 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7590 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7591 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7592 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7593 | MockRead("You are not authorized to view this page\r\n"), |
| 7594 | |
| 7595 | // Lastly we get the desired content. |
| 7596 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7597 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7598 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7599 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7600 | SequencedSocketData data0(reads0, writes0); |
| 7601 | StaticSocketDataProvider data1(reads1, writes1); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7602 | session_deps_.socket_factory->AddSocketDataProvider(&data0); |
| 7603 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7604 | |
| 7605 | SSLSocketDataProvider ssl0(ASYNC, OK); |
| 7606 | ssl0.next_proto = kProtoHTTP2; |
| 7607 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7608 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl0); |
| 7609 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7610 | |
| 7611 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7612 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7613 | |
| 7614 | TestCompletionCallback callback1; |
| 7615 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 7616 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7617 | |
| 7618 | rv = callback1.WaitForResult(); |
| 7619 | EXPECT_THAT(rv, IsOk()); |
| 7620 | |
| 7621 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 7622 | |
| 7623 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7624 | ASSERT_TRUE(response); |
| 7625 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
| 7626 | |
| 7627 | TestCompletionCallback callback2; |
| 7628 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7629 | rv = trans.RestartWithAuth( |
| 7630 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7631 | callback2.callback()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7632 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7633 | |
| 7634 | rv = callback2.WaitForResult(); |
| 7635 | EXPECT_THAT(rv, IsOk()); |
| 7636 | |
| 7637 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7638 | |
| 7639 | response = trans.GetResponseInfo(); |
| 7640 | ASSERT_TRUE(response); |
| 7641 | EXPECT_FALSE(response->auth_challenge); |
| 7642 | |
| 7643 | TestCompletionCallback callback3; |
| 7644 | |
| 7645 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
| 7646 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7647 | |
| 7648 | rv = callback3.WaitForResult(); |
| 7649 | EXPECT_THAT(rv, IsOk()); |
| 7650 | |
| 7651 | response = trans.GetResponseInfo(); |
| 7652 | ASSERT_TRUE(response); |
| 7653 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7654 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7655 | |
| 7656 | std::string response_data; |
| 7657 | rv = ReadTransaction(&trans, &response_data); |
| 7658 | EXPECT_THAT(rv, IsOk()); |
| 7659 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7660 | |
| 7661 | EXPECT_TRUE(data0.AllReadDataConsumed()); |
| 7662 | EXPECT_TRUE(data0.AllWriteDataConsumed()); |
| 7663 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7664 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7665 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7666 | |
| 7667 | // Test that, if we have an NTLM proxy and the origin resets the connection, we |
| 7668 | // do no retry forever checking for TLS version interference. This is a |
| 7669 | // regression test for https://crbug.com/823387. |
| 7670 | TEST_F(HttpNetworkTransactionTest, NTLMProxyTLSHandshakeReset) { |
| 7671 | // The NTLM test data expects the proxy to be named 'server'. The origin is |
| 7672 | // https://origin/. |
| 7673 | session_deps_.proxy_resolution_service = |
| 7674 | ProxyResolutionService::CreateFixedFromPacResult( |
| 7675 | "PROXY server", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7676 | |
| 7677 | SSLConfig config; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7678 | session_deps_.ssl_config_service = |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 7679 | std::make_unique<TestSSLConfigService>(config); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7680 | |
| 7681 | HttpRequestInfo request; |
| 7682 | request.method = "GET"; |
| 7683 | request.url = GURL("https://origin/"); |
| 7684 | request.traffic_annotation = |
| 7685 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7686 | |
| 7687 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 7688 | // to other auth schemes. |
| 7689 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 7690 | |
| 7691 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7692 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
| 7693 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7694 | |
| 7695 | // Generate the NTLM messages based on known test data. |
| 7696 | std::string negotiate_msg; |
| 7697 | std::string challenge_msg; |
| 7698 | std::string authenticate_msg; |
| 7699 | base::Base64Encode( |
| 7700 | base::StringPiece( |
| 7701 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7702 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7703 | &negotiate_msg); |
| 7704 | base::Base64Encode( |
| 7705 | base::StringPiece( |
| 7706 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7707 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7708 | &challenge_msg); |
| 7709 | base::Base64Encode( |
| 7710 | base::StringPiece( |
| 7711 | reinterpret_cast<const char*>( |
| 7712 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7713 | base::size( |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7714 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
| 7715 | &authenticate_msg); |
| 7716 | |
| 7717 | MockWrite data_writes[] = { |
| 7718 | // The initial CONNECT request. |
| 7719 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7720 | "Host: origin:443\r\n" |
| 7721 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7722 | |
| 7723 | // After restarting with an identity. |
| 7724 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7725 | "Host: origin:443\r\n" |
| 7726 | "Proxy-Connection: keep-alive\r\n" |
| 7727 | "Proxy-Authorization: NTLM "), |
| 7728 | MockWrite(negotiate_msg.c_str()), |
| 7729 | // End headers. |
| 7730 | MockWrite("\r\n\r\n"), |
| 7731 | |
| 7732 | // The second restart. |
| 7733 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7734 | "Host: origin:443\r\n" |
| 7735 | "Proxy-Connection: keep-alive\r\n" |
| 7736 | "Proxy-Authorization: NTLM "), |
| 7737 | MockWrite(authenticate_msg.c_str()), |
| 7738 | // End headers. |
| 7739 | MockWrite("\r\n\r\n"), |
| 7740 | }; |
| 7741 | |
| 7742 | MockRead data_reads[] = { |
| 7743 | // The initial NTLM response. |
| 7744 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 7745 | "Content-Length: 0\r\n" |
| 7746 | "Proxy-Authenticate: NTLM\r\n\r\n"), |
| 7747 | |
| 7748 | // The NTLM challenge message. |
| 7749 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 7750 | "Content-Length: 0\r\n" |
| 7751 | "Proxy-Authenticate: NTLM "), |
| 7752 | MockRead(challenge_msg.c_str()), |
| 7753 | // End headers. |
| 7754 | MockRead("\r\n\r\n"), |
| 7755 | |
| 7756 | // Finally the tunnel is established. |
| 7757 | MockRead("HTTP/1.1 200 Connected\r\n\r\n"), |
| 7758 | }; |
| 7759 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7760 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7761 | SSLSocketDataProvider data_ssl(ASYNC, ERR_CONNECTION_RESET); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7762 | StaticSocketDataProvider data2(data_reads, data_writes); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7763 | SSLSocketDataProvider data_ssl2(ASYNC, ERR_CONNECTION_RESET); |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 7764 | data_ssl2.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7765 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7766 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data_ssl); |
| 7767 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7768 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data_ssl2); |
| 7769 | |
| 7770 | // Start the transaction. The proxy responds with an NTLM authentication |
| 7771 | // request. |
| 7772 | TestCompletionCallback callback; |
| 7773 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7774 | int rv = callback.GetResult( |
| 7775 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 7776 | |
| 7777 | EXPECT_THAT(rv, IsOk()); |
| 7778 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 7779 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7780 | ASSERT_TRUE(response); |
| 7781 | EXPECT_TRUE(CheckNTLMProxyAuth(response->auth_challenge.get())); |
| 7782 | |
| 7783 | // Configure credentials. The proxy responds with the challenge message. |
| 7784 | rv = callback.GetResult(trans.RestartWithAuth( |
| 7785 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7786 | callback.callback())); |
| 7787 | EXPECT_THAT(rv, IsOk()); |
| 7788 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7789 | response = trans.GetResponseInfo(); |
| 7790 | ASSERT_TRUE(response); |
| 7791 | EXPECT_FALSE(response->auth_challenge); |
| 7792 | |
| 7793 | // Restart once more. The tunnel will be established and the the SSL handshake |
| 7794 | // will reset. The TLS 1.3 version interference probe will then kick in and |
| 7795 | // restart the process. The proxy responds with another NTLM authentiation |
| 7796 | // request, but we don't need to provide credentials as the cached ones work/ |
| 7797 | rv = callback.GetResult( |
| 7798 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7799 | EXPECT_THAT(rv, IsOk()); |
| 7800 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7801 | response = trans.GetResponseInfo(); |
| 7802 | ASSERT_TRUE(response); |
| 7803 | EXPECT_FALSE(response->auth_challenge); |
| 7804 | |
| 7805 | // The proxy responds with the NTLM challenge message. |
| 7806 | rv = callback.GetResult( |
| 7807 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7808 | EXPECT_THAT(rv, IsOk()); |
| 7809 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7810 | response = trans.GetResponseInfo(); |
| 7811 | ASSERT_TRUE(response); |
| 7812 | EXPECT_FALSE(response->auth_challenge); |
| 7813 | |
| 7814 | // Send the NTLM authenticate message. The tunnel is established and the |
| 7815 | // handshake resets again. We should not retry again. |
| 7816 | rv = callback.GetResult( |
| 7817 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7818 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
| 7819 | } |
| 7820 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7821 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7822 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7823 | // Test reading a server response which has only headers, and no body. |
| 7824 | // After some maximum number of bytes is consumed, the transaction should |
| 7825 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7826 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7827 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7828 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7829 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7830 | request.traffic_annotation = |
| 7831 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7832 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7833 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7834 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7835 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 7836 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 7837 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 7838 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7839 | |
| 7840 | MockRead data_reads[] = { |
| 7841 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7842 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7843 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7844 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7845 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7846 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7847 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7848 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7849 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7850 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7851 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7852 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7853 | |
| 7854 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7855 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7856 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7857 | |
| 7858 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 7859 | // establish tunnel. |
| 7860 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7861 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7862 | HttpRequestInfo request; |
| 7863 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7864 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7865 | request.traffic_annotation = |
| 7866 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7867 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7868 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 7869 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 7870 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 7871 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7872 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7873 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7874 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7875 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7876 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7877 | // Since we have proxy, should try to establish tunnel. |
| 7878 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7879 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7880 | "Host: www.example.org:443\r\n" |
| 7881 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7882 | }; |
| 7883 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 7884 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7885 | // connection. Usually a proxy would return 501 (not implemented), |
| 7886 | // or 200 (tunnel established). |
| 7887 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 7888 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 7889 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7890 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7891 | }; |
| 7892 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7893 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7894 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7895 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7896 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7897 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7898 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7899 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7900 | |
| 7901 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7902 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7903 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7904 | // Empty the current queue. This is necessary because idle sockets are |
| 7905 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7906 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7907 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7908 | // We now check to make sure the TCPClientSocket was not added back to |
| 7909 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7910 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7911 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7912 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7913 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7914 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7915 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7916 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7917 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7918 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7919 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7920 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7921 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7922 | request.traffic_annotation = |
| 7923 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7924 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7925 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7926 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7927 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7928 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7929 | MockRead data_reads[] = { |
| 7930 | // A part of the response body is received with the response headers. |
| 7931 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7932 | // The rest of the response body is received in two parts. |
| 7933 | MockRead("lo"), |
| 7934 | MockRead(" world"), |
| 7935 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7936 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7937 | }; |
| 7938 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7939 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7940 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7941 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7942 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7943 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7944 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7945 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7946 | |
| 7947 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7948 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7949 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7950 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7951 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7952 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7953 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7954 | std::string status_line = response->headers->GetStatusLine(); |
| 7955 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7956 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7957 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7958 | |
| 7959 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7960 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7961 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7962 | EXPECT_EQ("hello world", response_data); |
| 7963 | |
| 7964 | // Empty the current queue. This is necessary because idle sockets are |
| 7965 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7966 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7967 | |
| 7968 | // 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] | 7969 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7970 | } |
| 7971 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7972 | // Make sure that we recycle a SSL socket after reading all of the response |
| 7973 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7974 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7975 | HttpRequestInfo request; |
| 7976 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7977 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7978 | request.traffic_annotation = |
| 7979 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7980 | |
| 7981 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7982 | MockWrite( |
| 7983 | "GET / HTTP/1.1\r\n" |
| 7984 | "Host: www.example.org\r\n" |
| 7985 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7986 | }; |
| 7987 | |
| 7988 | MockRead data_reads[] = { |
| 7989 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7990 | MockRead("Content-Length: 11\r\n\r\n"), |
| 7991 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7992 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7993 | }; |
| 7994 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7995 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7996 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7997 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7998 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7999 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8000 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8001 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8002 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8003 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8004 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8005 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8006 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8007 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8008 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8009 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8010 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8011 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8012 | ASSERT_TRUE(response); |
| 8013 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8014 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8015 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8016 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8017 | |
| 8018 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8019 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8020 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8021 | EXPECT_EQ("hello world", response_data); |
| 8022 | |
| 8023 | // Empty the current queue. This is necessary because idle sockets are |
| 8024 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8025 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8026 | |
| 8027 | // 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] | 8028 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8029 | } |
| 8030 | |
| 8031 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 8032 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8033 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8034 | HttpRequestInfo request; |
| 8035 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8036 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8037 | request.traffic_annotation = |
| 8038 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8039 | |
| 8040 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8041 | MockWrite( |
| 8042 | "GET / HTTP/1.1\r\n" |
| 8043 | "Host: www.example.org\r\n" |
| 8044 | "Connection: keep-alive\r\n\r\n"), |
| 8045 | MockWrite( |
| 8046 | "GET / HTTP/1.1\r\n" |
| 8047 | "Host: www.example.org\r\n" |
| 8048 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8049 | }; |
| 8050 | |
| 8051 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 8052 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 8053 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8054 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8055 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 8056 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8057 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8058 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8059 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8060 | StaticSocketDataProvider data(data_reads, data_writes); |
| 8061 | StaticSocketDataProvider data2(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8062 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8063 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8064 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8065 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8066 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8067 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8068 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8069 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8070 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8071 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8072 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8073 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8074 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8075 | |
| 8076 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8077 | ASSERT_TRUE(response); |
| 8078 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8079 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8080 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8081 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8082 | |
| 8083 | std::string response_data; |
| 8084 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8085 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8086 | EXPECT_EQ("hello world", response_data); |
| 8087 | |
| 8088 | // Empty the current queue. This is necessary because idle sockets are |
| 8089 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8090 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8091 | |
| 8092 | // 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] | 8093 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8094 | |
| 8095 | // Now start the second transaction, which should reuse the previous socket. |
| 8096 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8097 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8098 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8099 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8100 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8101 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8102 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8103 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8104 | |
| 8105 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8106 | ASSERT_TRUE(response); |
| 8107 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8108 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8109 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8110 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8111 | |
| 8112 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8113 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8114 | EXPECT_EQ("hello world", response_data); |
| 8115 | |
| 8116 | // Empty the current queue. This is necessary because idle sockets are |
| 8117 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8118 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8119 | |
| 8120 | // 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] | 8121 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8122 | } |
| 8123 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8124 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 8125 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8126 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8127 | HttpRequestInfo request; |
| 8128 | request.method = "GET"; |
| 8129 | request.url = GURL("http://www.example.org/"); |
| 8130 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8131 | request.traffic_annotation = |
| 8132 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8133 | |
| 8134 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8135 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8136 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8137 | |
| 8138 | MockRead data_reads[] = { |
| 8139 | // A part of the response body is received with the response headers. |
| 8140 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 8141 | // The rest of the response body is received in two parts. |
| 8142 | MockRead("lo"), MockRead(" world"), |
| 8143 | MockRead("junk"), // Should not be read!! |
| 8144 | MockRead(SYNCHRONOUS, OK), |
| 8145 | }; |
| 8146 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8147 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8148 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8149 | |
| 8150 | TestCompletionCallback callback; |
| 8151 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8152 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8153 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8154 | |
| 8155 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8156 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8157 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8158 | ASSERT_TRUE(response); |
| 8159 | EXPECT_TRUE(response->headers); |
| 8160 | std::string status_line = response->headers->GetStatusLine(); |
| 8161 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 8162 | |
| 8163 | // Make memory critical notification and ensure the transaction still has been |
| 8164 | // operating right. |
| 8165 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8166 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8167 | base::RunLoop().RunUntilIdle(); |
| 8168 | |
| 8169 | // Socket should not be flushed as long as it is not idle. |
| 8170 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8171 | |
| 8172 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8173 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8174 | EXPECT_THAT(rv, IsOk()); |
| 8175 | EXPECT_EQ("hello world", response_data); |
| 8176 | |
| 8177 | // Empty the current queue. This is necessary because idle sockets are |
| 8178 | // added to the connection pool asynchronously with a PostTask. |
| 8179 | base::RunLoop().RunUntilIdle(); |
| 8180 | |
| 8181 | // We now check to make sure the socket was added back to the pool. |
| 8182 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8183 | |
| 8184 | // Idle sockets should be flushed now. |
| 8185 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8186 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8187 | base::RunLoop().RunUntilIdle(); |
| 8188 | |
| 8189 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8190 | } |
| 8191 | |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8192 | // Disable idle socket closing on memory pressure. |
| 8193 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 8194 | // low memory notification and ensure the socket pool is NOT flushed. |
| 8195 | TEST_F(HttpNetworkTransactionTest, NoFlushSocketPoolOnLowMemoryNotifications) { |
| 8196 | HttpRequestInfo request; |
| 8197 | request.method = "GET"; |
| 8198 | request.url = GURL("http://www.example.org/"); |
| 8199 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8200 | request.traffic_annotation = |
| 8201 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8202 | |
| 8203 | // Disable idle socket closing on memory pressure. |
| 8204 | session_deps_.disable_idle_sockets_close_on_memory_pressure = true; |
| 8205 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8206 | |
| 8207 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 8208 | |
| 8209 | MockRead data_reads[] = { |
| 8210 | // A part of the response body is received with the response headers. |
| 8211 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 8212 | // The rest of the response body is received in two parts. |
| 8213 | MockRead("lo"), MockRead(" world"), |
| 8214 | MockRead("junk"), // Should not be read!! |
| 8215 | MockRead(SYNCHRONOUS, OK), |
| 8216 | }; |
| 8217 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8218 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8219 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8220 | |
| 8221 | TestCompletionCallback callback; |
| 8222 | |
| 8223 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 8224 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8225 | |
| 8226 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8227 | |
| 8228 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 8229 | ASSERT_TRUE(response); |
| 8230 | EXPECT_TRUE(response->headers); |
| 8231 | std::string status_line = response->headers->GetStatusLine(); |
| 8232 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 8233 | |
| 8234 | // Make memory critical notification and ensure the transaction still has been |
| 8235 | // operating right. |
| 8236 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8237 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8238 | base::RunLoop().RunUntilIdle(); |
| 8239 | |
| 8240 | // Socket should not be flushed as long as it is not idle. |
| 8241 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8242 | |
| 8243 | std::string response_data; |
| 8244 | rv = ReadTransaction(&trans, &response_data); |
| 8245 | EXPECT_THAT(rv, IsOk()); |
| 8246 | EXPECT_EQ("hello world", response_data); |
| 8247 | |
| 8248 | // Empty the current queue. This is necessary because idle sockets are |
| 8249 | // added to the connection pool asynchronously with a PostTask. |
| 8250 | base::RunLoop().RunUntilIdle(); |
| 8251 | |
| 8252 | // We now check to make sure the socket was added back to the pool. |
| 8253 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8254 | |
| 8255 | // Idle sockets should NOT be flushed on moderate memory pressure. |
| 8256 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8257 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); |
| 8258 | base::RunLoop().RunUntilIdle(); |
| 8259 | |
| 8260 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8261 | |
| 8262 | // Idle sockets should NOT be flushed on critical memory pressure. |
| 8263 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8264 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8265 | base::RunLoop().RunUntilIdle(); |
| 8266 | |
| 8267 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8268 | } |
| 8269 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8270 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 8271 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8272 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8273 | HttpRequestInfo request; |
| 8274 | request.method = "GET"; |
| 8275 | request.url = GURL("https://www.example.org/"); |
| 8276 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8277 | request.traffic_annotation = |
| 8278 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8279 | |
| 8280 | MockWrite data_writes[] = { |
| 8281 | MockWrite("GET / HTTP/1.1\r\n" |
| 8282 | "Host: www.example.org\r\n" |
| 8283 | "Connection: keep-alive\r\n\r\n"), |
| 8284 | }; |
| 8285 | |
| 8286 | MockRead data_reads[] = { |
| 8287 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 8288 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 8289 | |
| 8290 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 8291 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8292 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8293 | StaticSocketDataProvider data(data_reads, data_writes); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8294 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8295 | |
| 8296 | TestCompletionCallback callback; |
| 8297 | |
| 8298 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8299 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8300 | |
| 8301 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8302 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8303 | |
| 8304 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8305 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8306 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8307 | ASSERT_TRUE(response); |
| 8308 | ASSERT_TRUE(response->headers); |
| 8309 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8310 | |
| 8311 | // Make memory critical notification and ensure the transaction still has been |
| 8312 | // operating right. |
| 8313 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8314 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8315 | base::RunLoop().RunUntilIdle(); |
| 8316 | |
| 8317 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 8318 | |
| 8319 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8320 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8321 | EXPECT_THAT(rv, IsOk()); |
| 8322 | EXPECT_EQ("hello world", response_data); |
| 8323 | |
| 8324 | // Empty the current queue. This is necessary because idle sockets are |
| 8325 | // added to the connection pool asynchronously with a PostTask. |
| 8326 | base::RunLoop().RunUntilIdle(); |
| 8327 | |
| 8328 | // We now check to make sure the socket was added back to the pool. |
| 8329 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 8330 | |
| 8331 | // Make memory notification once again and ensure idle socket is closed. |
| 8332 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8333 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8334 | base::RunLoop().RunUntilIdle(); |
| 8335 | |
| 8336 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 8337 | } |
| 8338 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8339 | // Make sure that we recycle a socket after a zero-length response. |
| 8340 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8341 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8342 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8343 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8344 | request.url = GURL( |
| 8345 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 8346 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 8347 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 8348 | "rt=prt.2642,ol.2649,xjs.2951"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8349 | request.traffic_annotation = |
| 8350 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8351 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8352 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8353 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8354 | MockRead data_reads[] = { |
| 8355 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 8356 | "Content-Length: 0\r\n" |
| 8357 | "Content-Type: text/html\r\n\r\n"), |
| 8358 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8359 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8360 | }; |
| 8361 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8362 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8363 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8364 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 8365 | // Transaction must be created after the MockReads, so it's destroyed before |
| 8366 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8367 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 8368 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8369 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8370 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8371 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8372 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8373 | |
| 8374 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8375 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8376 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8377 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8378 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8379 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8380 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8381 | std::string status_line = response->headers->GetStatusLine(); |
| 8382 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 8383 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8384 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8385 | |
| 8386 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8387 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8388 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8389 | EXPECT_EQ("", response_data); |
| 8390 | |
| 8391 | // Empty the current queue. This is necessary because idle sockets are |
| 8392 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8393 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8394 | |
| 8395 | // 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] | 8396 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8397 | } |
| 8398 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8399 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8400 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 8401 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8402 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 8403 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8404 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8405 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8406 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 8407 | // after use. |
| 8408 | request[0].method = "GET"; |
| 8409 | request[0].url = GURL("http://www.google.com/"); |
| 8410 | request[0].load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8411 | request[0].traffic_annotation = |
| 8412 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8413 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 8414 | // transaction 1. The first attempts fails when writing the POST data. |
| 8415 | // This causes the transaction to retry with a new socket. The second |
| 8416 | // attempt succeeds. |
| 8417 | request[1].method = "POST"; |
| 8418 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8419 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8420 | request[1].load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8421 | request[1].traffic_annotation = |
| 8422 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8423 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8424 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8425 | |
| 8426 | // The first socket is used for transaction 1 and the first attempt of |
| 8427 | // transaction 2. |
| 8428 | |
| 8429 | // The response of transaction 1. |
| 8430 | MockRead data_reads1[] = { |
| 8431 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 8432 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8433 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8434 | }; |
| 8435 | // The mock write results of transaction 1 and the first attempt of |
| 8436 | // transaction 2. |
| 8437 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8438 | MockWrite(SYNCHRONOUS, 64), // GET |
| 8439 | MockWrite(SYNCHRONOUS, 93), // POST |
| 8440 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8441 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8442 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8443 | |
| 8444 | // The second socket is used for the second attempt of transaction 2. |
| 8445 | |
| 8446 | // The response of transaction 2. |
| 8447 | MockRead data_reads2[] = { |
| 8448 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 8449 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8450 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8451 | }; |
| 8452 | // The mock write results of the second attempt of transaction 2. |
| 8453 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8454 | MockWrite(SYNCHRONOUS, 93), // POST |
| 8455 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8456 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8457 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8458 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8459 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8460 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8461 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8462 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8463 | "hello world", "welcome" |
| 8464 | }; |
| 8465 | |
| 8466 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8467 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8468 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8469 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8470 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8471 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8472 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8473 | |
| 8474 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8475 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8476 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8477 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8478 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8479 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8480 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8481 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8482 | |
| 8483 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8484 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8485 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8486 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 8487 | } |
| 8488 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8489 | |
| 8490 | // Test the request-challenge-retry sequence for basic auth when there is |
| 8491 | // 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] | 8492 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8493 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8494 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8495 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8496 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 8497 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8498 | request.traffic_annotation = |
| 8499 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 8500 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8501 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8502 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8503 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 8504 | // The password contains an escaped character -- for this test to pass it |
| 8505 | // will need to be unescaped by HttpNetworkTransaction. |
| 8506 | EXPECT_EQ("b%40r", request.url.password()); |
| 8507 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8508 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8509 | MockWrite( |
| 8510 | "GET / HTTP/1.1\r\n" |
| 8511 | "Host: www.example.org\r\n" |
| 8512 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8513 | }; |
| 8514 | |
| 8515 | MockRead data_reads1[] = { |
| 8516 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8517 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8518 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8519 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8520 | }; |
| 8521 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8522 | // After the challenge above, the transaction will be restarted using the |
| 8523 | // identity from the url (foo, b@r) to answer the challenge. |
| 8524 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8525 | MockWrite( |
| 8526 | "GET / HTTP/1.1\r\n" |
| 8527 | "Host: www.example.org\r\n" |
| 8528 | "Connection: keep-alive\r\n" |
| 8529 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8530 | }; |
| 8531 | |
| 8532 | MockRead data_reads2[] = { |
| 8533 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8534 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8535 | MockRead(SYNCHRONOUS, OK), |
| 8536 | }; |
| 8537 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8538 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8539 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8540 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8541 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8542 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8543 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8544 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8545 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8546 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8547 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8548 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8549 | |
| 8550 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8551 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8552 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8553 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8554 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8555 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8556 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8557 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8558 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8559 | |
| 8560 | // There is no challenge info, since the identity in URL worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8561 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8562 | |
| 8563 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8564 | |
| 8565 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8566 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8567 | } |
| 8568 | |
| 8569 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 8570 | // incorrect identity in the URL. The identity from the URL should be used only |
| 8571 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8572 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8573 | HttpRequestInfo request; |
| 8574 | request.method = "GET"; |
| 8575 | // Note: the URL has a username:password in it. The password "baz" is |
| 8576 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8577 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8578 | |
| 8579 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8580 | request.traffic_annotation = |
| 8581 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8582 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8583 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8584 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8585 | |
| 8586 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8587 | MockWrite( |
| 8588 | "GET / HTTP/1.1\r\n" |
| 8589 | "Host: www.example.org\r\n" |
| 8590 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8591 | }; |
| 8592 | |
| 8593 | MockRead data_reads1[] = { |
| 8594 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8595 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8596 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8597 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8598 | }; |
| 8599 | |
| 8600 | // After the challenge above, the transaction will be restarted using the |
| 8601 | // identity from the url (foo, baz) to answer the challenge. |
| 8602 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8603 | MockWrite( |
| 8604 | "GET / HTTP/1.1\r\n" |
| 8605 | "Host: www.example.org\r\n" |
| 8606 | "Connection: keep-alive\r\n" |
| 8607 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8608 | }; |
| 8609 | |
| 8610 | MockRead data_reads2[] = { |
| 8611 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8612 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8613 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8614 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8615 | }; |
| 8616 | |
| 8617 | // After the challenge above, the transaction will be restarted using the |
| 8618 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 8619 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8620 | MockWrite( |
| 8621 | "GET / HTTP/1.1\r\n" |
| 8622 | "Host: www.example.org\r\n" |
| 8623 | "Connection: keep-alive\r\n" |
| 8624 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8625 | }; |
| 8626 | |
| 8627 | MockRead data_reads3[] = { |
| 8628 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8629 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8630 | MockRead(SYNCHRONOUS, OK), |
| 8631 | }; |
| 8632 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8633 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8634 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 8635 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8636 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8637 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8638 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8639 | |
| 8640 | TestCompletionCallback callback1; |
| 8641 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8642 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8643 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8644 | |
| 8645 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8646 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8647 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8648 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8649 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8650 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8651 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8652 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8653 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8654 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8655 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8656 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8657 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8658 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 8659 | |
| 8660 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8661 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8662 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8663 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8664 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8665 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8666 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8667 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8668 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8669 | |
| 8670 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8671 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8672 | |
| 8673 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8674 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 8675 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8676 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 8677 | } |
| 8678 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8679 | |
| 8680 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 8681 | // correct identity in the URL, but its use is being suppressed. The identity |
| 8682 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8683 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8684 | HttpRequestInfo request; |
| 8685 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8686 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8687 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8688 | request.traffic_annotation = |
| 8689 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8690 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8691 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8692 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8693 | |
| 8694 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8695 | MockWrite( |
| 8696 | "GET / HTTP/1.1\r\n" |
| 8697 | "Host: www.example.org\r\n" |
| 8698 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8699 | }; |
| 8700 | |
| 8701 | MockRead data_reads1[] = { |
| 8702 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8703 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8704 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8705 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8706 | }; |
| 8707 | |
| 8708 | // After the challenge above, the transaction will be restarted using the |
| 8709 | // identity supplied by the user, not the one in the URL, to answer the |
| 8710 | // challenge. |
| 8711 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8712 | MockWrite( |
| 8713 | "GET / HTTP/1.1\r\n" |
| 8714 | "Host: www.example.org\r\n" |
| 8715 | "Connection: keep-alive\r\n" |
| 8716 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8717 | }; |
| 8718 | |
| 8719 | MockRead data_reads3[] = { |
| 8720 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8721 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8722 | MockRead(SYNCHRONOUS, OK), |
| 8723 | }; |
| 8724 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8725 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8726 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8727 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8728 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 8729 | |
| 8730 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8731 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8732 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8733 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8734 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8735 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8736 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8737 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8738 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8739 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 8740 | |
| 8741 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8742 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8743 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8744 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8745 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8746 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8747 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8748 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8749 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8750 | |
| 8751 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8752 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8753 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8754 | |
| 8755 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8756 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8757 | } |
| 8758 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8759 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8760 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8761 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8762 | |
| 8763 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 8764 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8765 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8766 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8767 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8768 | request.traffic_annotation = |
| 8769 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8770 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8771 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8772 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8773 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8774 | MockWrite( |
| 8775 | "GET /x/y/z HTTP/1.1\r\n" |
| 8776 | "Host: www.example.org\r\n" |
| 8777 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8778 | }; |
| 8779 | |
| 8780 | MockRead data_reads1[] = { |
| 8781 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8782 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8783 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8784 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8785 | }; |
| 8786 | |
| 8787 | // Resend with authorization (username=foo, password=bar) |
| 8788 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8789 | MockWrite( |
| 8790 | "GET /x/y/z HTTP/1.1\r\n" |
| 8791 | "Host: www.example.org\r\n" |
| 8792 | "Connection: keep-alive\r\n" |
| 8793 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8794 | }; |
| 8795 | |
| 8796 | // Sever accepts the authorization. |
| 8797 | MockRead data_reads2[] = { |
| 8798 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8799 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8800 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8801 | }; |
| 8802 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8803 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8804 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8805 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8806 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8807 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8808 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8809 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8810 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8811 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8812 | |
| 8813 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8814 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8815 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8816 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8817 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8818 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8819 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8820 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8821 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8822 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8823 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8824 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8825 | |
| 8826 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8827 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8828 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8829 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8830 | ASSERT_TRUE(response); |
| 8831 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8832 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8833 | } |
| 8834 | |
| 8835 | // ------------------------------------------------------------------------ |
| 8836 | |
| 8837 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 8838 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8839 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8840 | request.method = "GET"; |
| 8841 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 8842 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8843 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8844 | request.traffic_annotation = |
| 8845 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8846 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8847 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8848 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8849 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8850 | MockWrite( |
| 8851 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8852 | "Host: www.example.org\r\n" |
| 8853 | "Connection: keep-alive\r\n" |
| 8854 | // Send preemptive authorization for MyRealm1 |
| 8855 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8856 | }; |
| 8857 | |
| 8858 | // The server didn't like the preemptive authorization, and |
| 8859 | // challenges us for a different realm (MyRealm2). |
| 8860 | MockRead data_reads1[] = { |
| 8861 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8862 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 8863 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8864 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8865 | }; |
| 8866 | |
| 8867 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 8868 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8869 | MockWrite( |
| 8870 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8871 | "Host: www.example.org\r\n" |
| 8872 | "Connection: keep-alive\r\n" |
| 8873 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8874 | }; |
| 8875 | |
| 8876 | // Sever accepts the authorization. |
| 8877 | MockRead data_reads2[] = { |
| 8878 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8879 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8880 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8881 | }; |
| 8882 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8883 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8884 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8885 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8886 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8887 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8888 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8889 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8890 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8891 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8892 | |
| 8893 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8894 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8895 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8896 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8897 | ASSERT_TRUE(response); |
| 8898 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8899 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8900 | EXPECT_EQ("http://www.example.org", |
| 8901 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8902 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 8903 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8904 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8905 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8906 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8907 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 8908 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8909 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8910 | |
| 8911 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8912 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8913 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8914 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8915 | ASSERT_TRUE(response); |
| 8916 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8917 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8918 | } |
| 8919 | |
| 8920 | // ------------------------------------------------------------------------ |
| 8921 | |
| 8922 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 8923 | // succeed with preemptive authorization. |
| 8924 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8925 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8926 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8927 | request.url = GURL("http://www.example.org/x/y/z2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8928 | request.traffic_annotation = |
| 8929 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8930 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8931 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8932 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8933 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8934 | MockWrite( |
| 8935 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 8936 | "Host: www.example.org\r\n" |
| 8937 | "Connection: keep-alive\r\n" |
| 8938 | // The authorization for MyRealm1 gets sent preemptively |
| 8939 | // (since the url is in the same protection space) |
| 8940 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8941 | }; |
| 8942 | |
| 8943 | // Sever accepts the preemptive authorization |
| 8944 | MockRead data_reads1[] = { |
| 8945 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8946 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8947 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8948 | }; |
| 8949 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8950 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8951 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8952 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8953 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8954 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8955 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8956 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8957 | |
| 8958 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8959 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8960 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8961 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8962 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8963 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8964 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8965 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8966 | } |
| 8967 | |
| 8968 | // ------------------------------------------------------------------------ |
| 8969 | |
| 8970 | // Transaction 4: request another URL in MyRealm (however the |
| 8971 | // url is not known to belong to the protection space, so no pre-auth). |
| 8972 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8973 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8974 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8975 | request.url = GURL("http://www.example.org/x/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8976 | request.traffic_annotation = |
| 8977 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8978 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8979 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8980 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8981 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8982 | MockWrite( |
| 8983 | "GET /x/1 HTTP/1.1\r\n" |
| 8984 | "Host: www.example.org\r\n" |
| 8985 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8986 | }; |
| 8987 | |
| 8988 | MockRead data_reads1[] = { |
| 8989 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8990 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8991 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8992 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8993 | }; |
| 8994 | |
| 8995 | // Resend with authorization from MyRealm's cache. |
| 8996 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8997 | MockWrite( |
| 8998 | "GET /x/1 HTTP/1.1\r\n" |
| 8999 | "Host: www.example.org\r\n" |
| 9000 | "Connection: keep-alive\r\n" |
| 9001 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9002 | }; |
| 9003 | |
| 9004 | // Sever accepts the authorization. |
| 9005 | MockRead data_reads2[] = { |
| 9006 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9007 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9008 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9009 | }; |
| 9010 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9011 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9012 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9013 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9014 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9015 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9016 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9017 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9018 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9019 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9020 | |
| 9021 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9022 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9023 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9024 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9025 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9026 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9027 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9028 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9029 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9030 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9031 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9032 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9033 | ASSERT_TRUE(response); |
| 9034 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9035 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9036 | } |
| 9037 | |
| 9038 | // ------------------------------------------------------------------------ |
| 9039 | |
| 9040 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 9041 | // cached identity. Should invalidate and re-prompt. |
| 9042 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9043 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9044 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9045 | request.url = GURL("http://www.example.org/p/q/t"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9046 | request.traffic_annotation = |
| 9047 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9048 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9049 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9050 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9051 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9052 | MockWrite( |
| 9053 | "GET /p/q/t HTTP/1.1\r\n" |
| 9054 | "Host: www.example.org\r\n" |
| 9055 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9056 | }; |
| 9057 | |
| 9058 | MockRead data_reads1[] = { |
| 9059 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9060 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9061 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9062 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9063 | }; |
| 9064 | |
| 9065 | // Resend with authorization from cache for MyRealm. |
| 9066 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9067 | MockWrite( |
| 9068 | "GET /p/q/t HTTP/1.1\r\n" |
| 9069 | "Host: www.example.org\r\n" |
| 9070 | "Connection: keep-alive\r\n" |
| 9071 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9072 | }; |
| 9073 | |
| 9074 | // Sever rejects the authorization. |
| 9075 | MockRead data_reads2[] = { |
| 9076 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9077 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9078 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9079 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9080 | }; |
| 9081 | |
| 9082 | // At this point we should prompt for new credentials for MyRealm. |
| 9083 | // Restart with username=foo3, password=foo4. |
| 9084 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9085 | MockWrite( |
| 9086 | "GET /p/q/t HTTP/1.1\r\n" |
| 9087 | "Host: www.example.org\r\n" |
| 9088 | "Connection: keep-alive\r\n" |
| 9089 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9090 | }; |
| 9091 | |
| 9092 | // Sever accepts the authorization. |
| 9093 | MockRead data_reads3[] = { |
| 9094 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9095 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9096 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9097 | }; |
| 9098 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9099 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9100 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 9101 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9102 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9103 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 9104 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9105 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9106 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9107 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9108 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9109 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9110 | |
| 9111 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9112 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9113 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9114 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9115 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9116 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9117 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9118 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9119 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9120 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9121 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9122 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9123 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9124 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9125 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9126 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9127 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9128 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 9129 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9130 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9131 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9132 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9133 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9134 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9135 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9136 | ASSERT_TRUE(response); |
| 9137 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9138 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9139 | } |
| 9140 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9141 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9142 | // Tests that nonce count increments when multiple auth attempts |
| 9143 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9144 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 9145 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 9146 | new HttpAuthHandlerDigest::Factory(); |
| 9147 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 9148 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 9149 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9150 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9151 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9152 | |
| 9153 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 9154 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9155 | HttpRequestInfo request; |
| 9156 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9157 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9158 | request.traffic_annotation = |
| 9159 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9160 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9161 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9162 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9163 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9164 | MockWrite( |
| 9165 | "GET /x/y/z HTTP/1.1\r\n" |
| 9166 | "Host: www.example.org\r\n" |
| 9167 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9168 | }; |
| 9169 | |
| 9170 | MockRead data_reads1[] = { |
| 9171 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9172 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 9173 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9174 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9175 | }; |
| 9176 | |
| 9177 | // Resend with authorization (username=foo, password=bar) |
| 9178 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9179 | MockWrite( |
| 9180 | "GET /x/y/z HTTP/1.1\r\n" |
| 9181 | "Host: www.example.org\r\n" |
| 9182 | "Connection: keep-alive\r\n" |
| 9183 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 9184 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 9185 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 9186 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9187 | }; |
| 9188 | |
| 9189 | // Sever accepts the authorization. |
| 9190 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9191 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9192 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9193 | }; |
| 9194 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9195 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9196 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9197 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9198 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9199 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9200 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9201 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9202 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9203 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9204 | |
| 9205 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9206 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9207 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9208 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9209 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9210 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9211 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9212 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9213 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9214 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 9215 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9216 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9217 | |
| 9218 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9219 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9220 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9221 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9222 | ASSERT_TRUE(response); |
| 9223 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9224 | } |
| 9225 | |
| 9226 | // ------------------------------------------------------------------------ |
| 9227 | |
| 9228 | // Transaction 2: Request another resource in digestive's protection space. |
| 9229 | // This will preemptively add an Authorization header which should have an |
| 9230 | // "nc" value of 2 (as compared to 1 in the first use. |
| 9231 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9232 | HttpRequestInfo request; |
| 9233 | request.method = "GET"; |
| 9234 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 9235 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9236 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9237 | request.traffic_annotation = |
| 9238 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9239 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9240 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9241 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9242 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9243 | MockWrite( |
| 9244 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 9245 | "Host: www.example.org\r\n" |
| 9246 | "Connection: keep-alive\r\n" |
| 9247 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 9248 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 9249 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 9250 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9251 | }; |
| 9252 | |
| 9253 | // Sever accepts the authorization. |
| 9254 | MockRead data_reads1[] = { |
| 9255 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9256 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9257 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9258 | }; |
| 9259 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9260 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9261 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9262 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9263 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9264 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9265 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9266 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9267 | |
| 9268 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9269 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9270 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9271 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9272 | ASSERT_TRUE(response); |
| 9273 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9274 | } |
| 9275 | } |
| 9276 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9277 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9278 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9279 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9280 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9281 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9282 | |
| 9283 | // Setup some state (which we expect ResetStateForRestart() will clear). |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 9284 | trans.read_buf_ = base::MakeRefCounted<IOBuffer>(15); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9285 | trans.read_buf_len_ = 15; |
| 9286 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9287 | |
| 9288 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9289 | HttpResponseInfo* response = &trans.response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9290 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 9291 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9292 | response->response_time = base::Time::Now(); |
| 9293 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9294 | |
| 9295 | { // Setup state for response_.vary_data |
| 9296 | HttpRequestInfo request; |
| 9297 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 9298 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 9299 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9300 | request.extra_headers.SetHeader("Foo", "1"); |
| 9301 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9302 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9303 | } |
| 9304 | |
| 9305 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9306 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9307 | |
| 9308 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9309 | EXPECT_FALSE(trans.read_buf_); |
| 9310 | EXPECT_EQ(0, trans.read_buf_len_); |
| 9311 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9312 | EXPECT_FALSE(response->auth_challenge); |
| 9313 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 9314 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 9315 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9316 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9317 | } |
| 9318 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9319 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9320 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9321 | HttpRequestInfo request; |
| 9322 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9323 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9324 | request.traffic_annotation = |
| 9325 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9326 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9327 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9328 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9329 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9330 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9331 | MockWrite( |
| 9332 | "GET / HTTP/1.1\r\n" |
| 9333 | "Host: www.example.org\r\n" |
| 9334 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9335 | }; |
| 9336 | |
| 9337 | MockRead data_reads[] = { |
| 9338 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9339 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9340 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9341 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9342 | }; |
| 9343 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 9344 | StaticSocketDataProvider ssl_bad_certificate; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9345 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9346 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9347 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9348 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9349 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9350 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9351 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 9352 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9353 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9354 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9355 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9356 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9357 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9358 | |
| 9359 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9360 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9361 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9362 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9363 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9364 | |
| 9365 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9366 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9367 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9368 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9369 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9370 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9371 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9372 | } |
| 9373 | |
| 9374 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 9375 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9376 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9377 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9378 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9379 | |
| 9380 | HttpRequestInfo request; |
| 9381 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9382 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9383 | request.traffic_annotation = |
| 9384 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9385 | |
| 9386 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9387 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9388 | "Host: www.example.org:443\r\n" |
| 9389 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9390 | }; |
| 9391 | |
| 9392 | MockRead proxy_reads[] = { |
| 9393 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9394 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9395 | }; |
| 9396 | |
| 9397 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9398 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9399 | "Host: www.example.org:443\r\n" |
| 9400 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9401 | MockWrite("GET / HTTP/1.1\r\n" |
| 9402 | "Host: www.example.org\r\n" |
| 9403 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9404 | }; |
| 9405 | |
| 9406 | MockRead data_reads[] = { |
| 9407 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9408 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9409 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9410 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9411 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9412 | }; |
| 9413 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9414 | StaticSocketDataProvider ssl_bad_certificate(proxy_reads, proxy_writes); |
| 9415 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9416 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9417 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9418 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9419 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9420 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9421 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 9422 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9423 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9424 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9425 | |
| 9426 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9427 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9428 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9429 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9430 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9431 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9432 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9433 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9434 | |
| 9435 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9436 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9437 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9438 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9439 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9440 | |
| 9441 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9442 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9443 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9444 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9445 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9446 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9447 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9448 | } |
| 9449 | } |
| 9450 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9451 | |
| 9452 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9453 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9454 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9455 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9456 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9457 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9458 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9459 | |
| 9460 | HttpRequestInfo request; |
| 9461 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9462 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9463 | request.traffic_annotation = |
| 9464 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9465 | |
| 9466 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9467 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9468 | "Host: www.example.org:443\r\n" |
| 9469 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9470 | MockWrite("GET / HTTP/1.1\r\n" |
| 9471 | "Host: www.example.org\r\n" |
| 9472 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9473 | }; |
| 9474 | |
| 9475 | MockRead data_reads[] = { |
| 9476 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9477 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9478 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9479 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9480 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9481 | }; |
| 9482 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9483 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9484 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 9485 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9486 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9487 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9488 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 9489 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9490 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9491 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9492 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9493 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9494 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9495 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9496 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9497 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9498 | |
| 9499 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9500 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9501 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9502 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9503 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9504 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9505 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9506 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9507 | EXPECT_EQ(200, response->headers->response_code()); |
| 9508 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9509 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9510 | |
| 9511 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9512 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9513 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9514 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9515 | } |
| 9516 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9517 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9518 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9519 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9520 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9521 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9522 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9523 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9524 | |
| 9525 | HttpRequestInfo request; |
| 9526 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9527 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9528 | request.traffic_annotation = |
| 9529 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9530 | |
| 9531 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9532 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9533 | "Host: www.example.org:443\r\n" |
| 9534 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9535 | }; |
| 9536 | |
| 9537 | MockRead data_reads[] = { |
| 9538 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 9539 | MockRead("Location: http://login.example.com/\r\n"), |
| 9540 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9541 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9542 | }; |
| 9543 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9544 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9545 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9546 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9547 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9548 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9549 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9550 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9551 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9552 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9553 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9554 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9555 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9556 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9557 | |
| 9558 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9559 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9560 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9561 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9562 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9563 | |
| 9564 | EXPECT_EQ(302, response->headers->response_code()); |
| 9565 | std::string url; |
| 9566 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 9567 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9568 | |
| 9569 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 9570 | // timing for the proxy connection instead of the connection to the host, |
| 9571 | // and no send / receive times. |
| 9572 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 9573 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9574 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9575 | |
| 9576 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 9577 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9578 | |
| 9579 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 9580 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 9581 | load_timing_info.proxy_resolve_end); |
| 9582 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 9583 | load_timing_info.connect_timing.connect_start); |
| 9584 | ExpectConnectTimingHasTimes( |
| 9585 | load_timing_info.connect_timing, |
| 9586 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9587 | |
| 9588 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 9589 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 9590 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9591 | } |
| 9592 | |
| 9593 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9594 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9595 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9596 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9597 | |
| 9598 | HttpRequestInfo request; |
| 9599 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9600 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9601 | request.traffic_annotation = |
| 9602 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9603 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9604 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9605 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9606 | spdy::SpdySerializedFrame goaway( |
| 9607 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9608 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9609 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
| 9610 | CreateMockWrite(goaway, 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9611 | }; |
| 9612 | |
| 9613 | static const char* const kExtraHeaders[] = { |
| 9614 | "location", |
| 9615 | "http://login.example.com/", |
| 9616 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9617 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9618 | "302", kExtraHeaders, base::size(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9619 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9620 | CreateMockRead(resp, 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9621 | }; |
| 9622 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9623 | SequencedSocketData data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9624 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9625 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9626 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9627 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9628 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9629 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9630 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9631 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9632 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9633 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9634 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9635 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9636 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9637 | |
| 9638 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9639 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9640 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9641 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9642 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9643 | |
| 9644 | EXPECT_EQ(302, response->headers->response_code()); |
| 9645 | std::string url; |
| 9646 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 9647 | EXPECT_EQ("http://login.example.com/", url); |
| 9648 | } |
| 9649 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 9650 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9651 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9652 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9653 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9654 | |
| 9655 | HttpRequestInfo request; |
| 9656 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9657 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9658 | request.traffic_annotation = |
| 9659 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9660 | |
| 9661 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9662 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9663 | "Host: www.example.org:443\r\n" |
| 9664 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9665 | }; |
| 9666 | |
| 9667 | MockRead data_reads[] = { |
| 9668 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 9669 | MockRead("Content-Length: 23\r\n\r\n"), |
| 9670 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9671 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9672 | }; |
| 9673 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9674 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9675 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9676 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9677 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9678 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9679 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9680 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9681 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9682 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9683 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9684 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9685 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9686 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9687 | |
| 9688 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9689 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9690 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 9691 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9692 | } |
| 9693 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 9694 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9695 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9696 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9697 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9698 | |
| 9699 | HttpRequestInfo request; |
| 9700 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9701 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9702 | request.traffic_annotation = |
| 9703 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9704 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9705 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9706 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9707 | spdy::SpdySerializedFrame rst( |
| 9708 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9709 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9710 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9711 | }; |
| 9712 | |
| 9713 | static const char* const kExtraHeaders[] = { |
| 9714 | "location", |
| 9715 | "http://login.example.com/", |
| 9716 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9717 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9718 | "404", kExtraHeaders, base::size(kExtraHeaders) / 2, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9719 | spdy::SpdySerializedFrame body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9720 | spdy_util_.ConstructSpdyDataFrame(1, "The host does not exist", true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9721 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9722 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9723 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9724 | }; |
| 9725 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9726 | SequencedSocketData data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9727 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9728 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9729 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9730 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9731 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9732 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9733 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9734 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9735 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9736 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9737 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9738 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9739 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9740 | |
| 9741 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9742 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9743 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 9744 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9745 | } |
| 9746 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9747 | // Test the request-challenge-retry sequence for basic auth, through |
| 9748 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9749 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9750 | HttpRequestInfo request; |
| 9751 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9752 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9753 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 9754 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9755 | request.traffic_annotation = |
| 9756 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9757 | |
| 9758 | // Configure against https proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9759 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9760 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9761 | "HTTPS myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9762 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9763 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9764 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9765 | |
| 9766 | // Since we have proxy, should try to establish tunnel. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9767 | spdy::SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9768 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9769 | spdy::SpdySerializedFrame rst( |
| 9770 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9771 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9772 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9773 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9774 | // be issuing -- the final header line contains the credentials. |
| 9775 | const char* const kAuthCredentials[] = { |
| 9776 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 9777 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9778 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9779 | kAuthCredentials, base::size(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9780 | HostPortPair("www.example.org", 443))); |
| 9781 | // fetch https://www.example.org/ via HTTP |
| 9782 | const char get[] = |
| 9783 | "GET / HTTP/1.1\r\n" |
| 9784 | "Host: www.example.org\r\n" |
| 9785 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9786 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9787 | spdy_util_.ConstructSpdyDataFrame(3, get, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9788 | |
| 9789 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9790 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 9791 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9792 | }; |
| 9793 | |
| 9794 | // The proxy responds to the connect with a 407, using a persistent |
| 9795 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 9796 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9797 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9798 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 9799 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9800 | spdy::SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9801 | kAuthStatus, kAuthChallenge, base::size(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9802 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9803 | spdy::SpdySerializedFrame conn_resp( |
| 9804 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9805 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 9806 | "Content-Length: 5\r\n\r\n"; |
| 9807 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9808 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9809 | spdy_util_.ConstructSpdyDataFrame(3, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9810 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9811 | spdy_util_.ConstructSpdyDataFrame(3, "hello", false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9812 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9813 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 9814 | CreateMockRead(conn_resp, 4, ASYNC), |
| 9815 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 9816 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9817 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9818 | }; |
| 9819 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9820 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9821 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9822 | // Negotiate SPDY to the proxy |
| 9823 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9824 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9825 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9826 | // Vanilla SSL to the server |
| 9827 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9828 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9829 | |
| 9830 | TestCompletionCallback callback1; |
| 9831 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9832 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9833 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9834 | |
| 9835 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9836 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9837 | |
| 9838 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9839 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 9840 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9841 | log.GetEntries(&entries); |
| 9842 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 9843 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 9844 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9845 | ExpectLogContainsSomewhere( |
| 9846 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 9847 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 9848 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9849 | |
| 9850 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9851 | ASSERT_TRUE(response); |
| 9852 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9853 | EXPECT_EQ(407, response->headers->response_code()); |
| 9854 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9855 | EXPECT_TRUE(response->auth_challenge); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 9856 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9857 | |
| 9858 | TestCompletionCallback callback2; |
| 9859 | |
| 9860 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 9861 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9862 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9863 | |
| 9864 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9865 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9866 | |
| 9867 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9868 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9869 | |
| 9870 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9871 | EXPECT_EQ(200, response->headers->response_code()); |
| 9872 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 9873 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9874 | |
| 9875 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9876 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9877 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9878 | LoadTimingInfo load_timing_info; |
| 9879 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 9880 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9881 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9882 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9883 | trans.reset(); |
| 9884 | session->CloseAllConnections(); |
| 9885 | } |
| 9886 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9887 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 9888 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9889 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9890 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9891 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9892 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 9893 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9894 | HttpRequestInfo request; |
| 9895 | HttpRequestInfo push_request; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9896 | request.traffic_annotation = |
| 9897 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9898 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9899 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9900 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9901 | push_request.method = "GET"; |
| 9902 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9903 | push_request.traffic_annotation = |
| 9904 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9905 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9906 | // Configure against https proxy server "myproxy:443". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9907 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9908 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9909 | "HTTPS myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9910 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9911 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9912 | |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 9913 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 9914 | proxy_delegate.get()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9915 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9916 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9917 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9918 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9919 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9920 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9921 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9922 | |
| 9923 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9924 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9925 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9926 | }; |
| 9927 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9928 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 9929 | NULL, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
| 9930 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9931 | spdy::SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9932 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9933 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9934 | spdy::SpdySerializedFrame stream1_body( |
| 9935 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9936 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9937 | spdy::SpdySerializedFrame stream2_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9938 | spdy_util_.ConstructSpdyDataFrame(2, "pushed", true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9939 | |
| 9940 | MockRead spdy_reads[] = { |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 9941 | CreateMockRead(stream2_syn, 1, ASYNC), |
| 9942 | CreateMockRead(stream1_reply, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9943 | CreateMockRead(stream1_body, 4, ASYNC), |
| 9944 | CreateMockRead(stream2_body, 5, ASYNC), |
| 9945 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9946 | }; |
| 9947 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9948 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9949 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9950 | // Negotiate SPDY to the proxy |
| 9951 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9952 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9953 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9954 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9955 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9956 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9957 | TestCompletionCallback callback; |
| 9958 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9959 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9960 | |
| 9961 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9962 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9963 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9964 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9965 | auto push_trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9966 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9967 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9968 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9969 | |
| 9970 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9971 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9972 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 9973 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9974 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9975 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9976 | |
| 9977 | EXPECT_EQ(200, response->headers->response_code()); |
| 9978 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9979 | |
| 9980 | std::string response_data; |
| 9981 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9982 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9983 | EXPECT_EQ("hello!", response_data); |
| 9984 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9985 | LoadTimingInfo load_timing_info; |
| 9986 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 9987 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9988 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9989 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9990 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9991 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9992 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 9993 | |
| 9994 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9995 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9996 | EXPECT_EQ("pushed", response_data); |
| 9997 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9998 | LoadTimingInfo push_load_timing_info; |
| 9999 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 10000 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 10001 | // The transactions should share a socket ID, despite being for different |
| 10002 | // origins. |
| 10003 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 10004 | push_load_timing_info.socket_log_id); |
| 10005 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10006 | trans.reset(); |
| 10007 | push_trans.reset(); |
| 10008 | session->CloseAllConnections(); |
| 10009 | } |
| 10010 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10011 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10012 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10013 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10014 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10015 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 10016 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10017 | HttpRequestInfo request; |
| 10018 | |
| 10019 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10020 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10021 | request.traffic_annotation = |
| 10022 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10023 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10024 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10025 | "https://myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10026 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10027 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10028 | |
| 10029 | // Enable cross-origin push. |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10030 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10031 | proxy_delegate.get()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10032 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10033 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10034 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10035 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10036 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10037 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10038 | spdy::SpdySerializedFrame push_rst( |
| 10039 | spdy_util_.ConstructSpdyRstStream(2, spdy::ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10040 | |
| 10041 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10042 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10043 | }; |
| 10044 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10045 | spdy::SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10046 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10047 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10048 | spdy::SpdySerializedFrame stream1_body( |
| 10049 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10050 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10051 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 10052 | NULL, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10053 | |
| 10054 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10055 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 10056 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 10057 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 10058 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10059 | }; |
| 10060 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10061 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10062 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10063 | // Negotiate SPDY to the proxy |
| 10064 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10065 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10066 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10067 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10068 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10069 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10070 | TestCompletionCallback callback; |
| 10071 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10072 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10073 | |
| 10074 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10075 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10076 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10077 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10078 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10079 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10080 | |
| 10081 | EXPECT_EQ(200, response->headers->response_code()); |
| 10082 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10083 | |
| 10084 | std::string response_data; |
| 10085 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10086 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10087 | EXPECT_EQ("hello!", response_data); |
| 10088 | |
| 10089 | trans.reset(); |
| 10090 | session->CloseAllConnections(); |
| 10091 | } |
| 10092 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10093 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 10094 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10095 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10096 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10097 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10098 | proxy_delegate->set_trusted_spdy_proxy( |
| 10099 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 10100 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10101 | HttpRequestInfo request; |
| 10102 | |
| 10103 | request.method = "GET"; |
| 10104 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10105 | request.traffic_annotation = |
| 10106 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10107 | |
| 10108 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10109 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10110 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10111 | BoundTestNetLog log; |
| 10112 | session_deps_.net_log = log.bound().net_log(); |
| 10113 | |
| 10114 | // Enable cross-origin push. |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10115 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10116 | proxy_delegate.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10117 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10118 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10119 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10120 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10121 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10122 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10123 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10124 | |
| 10125 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10126 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10127 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10128 | }; |
| 10129 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10130 | spdy::SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10131 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10132 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10133 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 096cf05 | 2017-08-08 23:55:33 | [diff] [blame] | 10134 | nullptr, 0, 2, 1, "http://www.example.org/foo.dat")); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 10135 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10136 | spdy::SpdySerializedFrame stream1_body( |
| 10137 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10138 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10139 | spdy::SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10140 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10141 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10142 | spdy::SpdySerializedFrame stream2_body( |
| 10143 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10144 | |
| 10145 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10146 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 10147 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10148 | CreateMockRead(stream1_body, 4, ASYNC), |
| 10149 | CreateMockRead(stream2_body, 5, ASYNC), |
| 10150 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10151 | }; |
| 10152 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10153 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10154 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 10155 | // Negotiate SPDY to the proxy |
| 10156 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10157 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10158 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 10159 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10160 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10161 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10162 | TestCompletionCallback callback; |
| 10163 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10164 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10165 | |
| 10166 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10167 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10168 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10169 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10170 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10171 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10172 | |
| 10173 | EXPECT_EQ(200, response->headers->response_code()); |
| 10174 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10175 | |
| 10176 | std::string response_data; |
| 10177 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10178 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10179 | EXPECT_EQ("hello!", response_data); |
| 10180 | |
| 10181 | trans.reset(); |
| 10182 | session->CloseAllConnections(); |
| 10183 | } |
| 10184 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10185 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 10186 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10187 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10188 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10189 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10190 | |
| 10191 | HttpRequestInfo request; |
| 10192 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10193 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10194 | request.traffic_annotation = |
| 10195 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10196 | |
| 10197 | // Attempt to fetch the URL from a server with a bad cert |
| 10198 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10199 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10200 | "Host: www.example.org:443\r\n" |
| 10201 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10202 | }; |
| 10203 | |
| 10204 | MockRead bad_cert_reads[] = { |
| 10205 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10206 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10207 | }; |
| 10208 | |
| 10209 | // Attempt to fetch the URL with a good cert |
| 10210 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10211 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10212 | "Host: www.example.org:443\r\n" |
| 10213 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10214 | MockWrite("GET / HTTP/1.1\r\n" |
| 10215 | "Host: www.example.org\r\n" |
| 10216 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10217 | }; |
| 10218 | |
| 10219 | MockRead good_cert_reads[] = { |
| 10220 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 10221 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10222 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10223 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10224 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10225 | }; |
| 10226 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10227 | StaticSocketDataProvider ssl_bad_certificate(bad_cert_reads, bad_cert_writes); |
| 10228 | StaticSocketDataProvider data(good_cert_reads, good_data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10229 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 10230 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10231 | |
| 10232 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10233 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10234 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 10235 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10236 | |
| 10237 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10238 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10239 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10240 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10241 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10242 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10243 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10244 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10245 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10246 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10247 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10248 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10249 | |
| 10250 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10251 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10252 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10253 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10254 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10255 | |
| 10256 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10257 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10258 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10259 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10260 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10261 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10262 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10263 | } |
| 10264 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10265 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10266 | HttpRequestInfo request; |
| 10267 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10268 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10269 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 10270 | "Chromium Ultra Awesome X Edition"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10271 | request.traffic_annotation = |
| 10272 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10273 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10274 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10275 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10276 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10277 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10278 | MockWrite( |
| 10279 | "GET / HTTP/1.1\r\n" |
| 10280 | "Host: www.example.org\r\n" |
| 10281 | "Connection: keep-alive\r\n" |
| 10282 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10283 | }; |
| 10284 | |
| 10285 | // Lastly, the server responds with the actual content. |
| 10286 | MockRead data_reads[] = { |
| 10287 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10288 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10289 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10290 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10291 | }; |
| 10292 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10293 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10294 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10295 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10296 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10297 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10298 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10299 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10300 | |
| 10301 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10302 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10303 | } |
| 10304 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10305 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10306 | HttpRequestInfo request; |
| 10307 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10308 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10309 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 10310 | "Chromium Ultra Awesome X Edition"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10311 | request.traffic_annotation = |
| 10312 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10313 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10314 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10315 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10316 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10317 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10318 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10319 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10320 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10321 | "Host: www.example.org:443\r\n" |
| 10322 | "Proxy-Connection: keep-alive\r\n" |
| 10323 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10324 | }; |
| 10325 | MockRead data_reads[] = { |
| 10326 | // Return an error, so the transaction stops here (this test isn't |
| 10327 | // interested in the rest). |
| 10328 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 10329 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 10330 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 10331 | }; |
| 10332 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10333 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10334 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10335 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10336 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10337 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10338 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10339 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10340 | |
| 10341 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10342 | EXPECT_THAT(rv, IsOk()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10343 | } |
| 10344 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10345 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10346 | HttpRequestInfo request; |
| 10347 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10348 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 10349 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 10350 | "http://the.previous.site.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10351 | request.traffic_annotation = |
| 10352 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10353 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10354 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10355 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10356 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10357 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10358 | MockWrite( |
| 10359 | "GET / HTTP/1.1\r\n" |
| 10360 | "Host: www.example.org\r\n" |
| 10361 | "Connection: keep-alive\r\n" |
| 10362 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10363 | }; |
| 10364 | |
| 10365 | // Lastly, the server responds with the actual content. |
| 10366 | MockRead data_reads[] = { |
| 10367 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10368 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10369 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10370 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10371 | }; |
| 10372 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10373 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10374 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10375 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10376 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10377 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10378 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10379 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10380 | |
| 10381 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10382 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10383 | } |
| 10384 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10385 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10386 | HttpRequestInfo request; |
| 10387 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10388 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10389 | request.traffic_annotation = |
| 10390 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10391 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10392 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10393 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10394 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10395 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10396 | MockWrite( |
| 10397 | "POST / HTTP/1.1\r\n" |
| 10398 | "Host: www.example.org\r\n" |
| 10399 | "Connection: keep-alive\r\n" |
| 10400 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10401 | }; |
| 10402 | |
| 10403 | // Lastly, the server responds with the actual content. |
| 10404 | MockRead data_reads[] = { |
| 10405 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10406 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10407 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10408 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10409 | }; |
| 10410 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10411 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10412 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10413 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10414 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10415 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10416 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10417 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10418 | |
| 10419 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10420 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10421 | } |
| 10422 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10423 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10424 | HttpRequestInfo request; |
| 10425 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10426 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10427 | request.traffic_annotation = |
| 10428 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10429 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10430 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10431 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10432 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10433 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10434 | MockWrite( |
| 10435 | "PUT / HTTP/1.1\r\n" |
| 10436 | "Host: www.example.org\r\n" |
| 10437 | "Connection: keep-alive\r\n" |
| 10438 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10439 | }; |
| 10440 | |
| 10441 | // Lastly, the server responds with the actual content. |
| 10442 | MockRead data_reads[] = { |
| 10443 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10444 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10445 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10446 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10447 | }; |
| 10448 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10449 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10450 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10451 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10452 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10453 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10454 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10455 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10456 | |
| 10457 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10458 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10459 | } |
| 10460 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10461 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10462 | HttpRequestInfo request; |
| 10463 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10464 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10465 | request.traffic_annotation = |
| 10466 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10467 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10468 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10469 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10470 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10471 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 10472 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 10473 | "Host: www.example.org\r\n" |
| 10474 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10475 | }; |
| 10476 | |
| 10477 | // Lastly, the server responds with the actual content. |
| 10478 | MockRead data_reads[] = { |
| 10479 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10480 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10481 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10482 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10483 | }; |
| 10484 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10485 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10486 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10487 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10488 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10489 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10490 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10491 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10492 | |
| 10493 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10494 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10495 | } |
| 10496 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10497 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10498 | HttpRequestInfo request; |
| 10499 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10500 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10501 | request.load_flags = LOAD_BYPASS_CACHE; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10502 | request.traffic_annotation = |
| 10503 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10504 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10505 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10506 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10507 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10508 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10509 | MockWrite( |
| 10510 | "GET / HTTP/1.1\r\n" |
| 10511 | "Host: www.example.org\r\n" |
| 10512 | "Connection: keep-alive\r\n" |
| 10513 | "Pragma: no-cache\r\n" |
| 10514 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10515 | }; |
| 10516 | |
| 10517 | // Lastly, the server responds with the actual content. |
| 10518 | MockRead data_reads[] = { |
| 10519 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10520 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10521 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10522 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10523 | }; |
| 10524 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10525 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10526 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10527 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10528 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10529 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10530 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10531 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10532 | |
| 10533 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10534 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10535 | } |
| 10536 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10537 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10538 | HttpRequestInfo request; |
| 10539 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10540 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10541 | request.load_flags = LOAD_VALIDATE_CACHE; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10542 | request.traffic_annotation = |
| 10543 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10544 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10545 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10546 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10547 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10548 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10549 | MockWrite( |
| 10550 | "GET / HTTP/1.1\r\n" |
| 10551 | "Host: www.example.org\r\n" |
| 10552 | "Connection: keep-alive\r\n" |
| 10553 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10554 | }; |
| 10555 | |
| 10556 | // Lastly, the server responds with the actual content. |
| 10557 | MockRead data_reads[] = { |
| 10558 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10559 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10560 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10561 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10562 | }; |
| 10563 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10564 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10565 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10566 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10567 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10568 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10569 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10570 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10571 | |
| 10572 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10573 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10574 | } |
| 10575 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10576 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10577 | HttpRequestInfo request; |
| 10578 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10579 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10580 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10581 | request.traffic_annotation = |
| 10582 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10583 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10584 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10585 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10586 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10587 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10588 | MockWrite( |
| 10589 | "GET / HTTP/1.1\r\n" |
| 10590 | "Host: www.example.org\r\n" |
| 10591 | "Connection: keep-alive\r\n" |
| 10592 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10593 | }; |
| 10594 | |
| 10595 | // Lastly, the server responds with the actual content. |
| 10596 | MockRead data_reads[] = { |
| 10597 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10598 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10599 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10600 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10601 | }; |
| 10602 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10603 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10604 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10605 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10606 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10607 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10608 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10609 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10610 | |
| 10611 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10612 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10613 | } |
| 10614 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10615 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10616 | HttpRequestInfo request; |
| 10617 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10618 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10619 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 10620 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 10621 | request.extra_headers.SetHeader("FoO", "bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10622 | request.traffic_annotation = |
| 10623 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10624 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10625 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10626 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10627 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10628 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10629 | MockWrite( |
| 10630 | "GET / HTTP/1.1\r\n" |
| 10631 | "Host: www.example.org\r\n" |
| 10632 | "Connection: keep-alive\r\n" |
| 10633 | "referer: www.foo.com\r\n" |
| 10634 | "hEllo: Kitty\r\n" |
| 10635 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10636 | }; |
| 10637 | |
| 10638 | // Lastly, the server responds with the actual content. |
| 10639 | MockRead data_reads[] = { |
| 10640 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10641 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10642 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10643 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10644 | }; |
| 10645 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10646 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10647 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10648 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10649 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10650 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10651 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10652 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10653 | |
| 10654 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10655 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10656 | } |
| 10657 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10658 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10659 | HttpRequestInfo request; |
| 10660 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10661 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10662 | request.traffic_annotation = |
| 10663 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10664 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10665 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10666 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10667 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10668 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10669 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10670 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10671 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10672 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10673 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10674 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 10675 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10676 | |
| 10677 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10678 | MockWrite(ASYNC, write_buffer, base::size(write_buffer)), |
| 10679 | MockWrite("GET / HTTP/1.1\r\n" |
| 10680 | "Host: www.example.org\r\n" |
| 10681 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10682 | |
| 10683 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10684 | MockRead(ASYNC, read_buffer, base::size(read_buffer)), |
| 10685 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10686 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10687 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10688 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10689 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10690 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10691 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10692 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10693 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10694 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10695 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10696 | |
| 10697 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10698 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10699 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10700 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10701 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10702 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10703 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10704 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10705 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10706 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10707 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10708 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10709 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10710 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10711 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10712 | EXPECT_EQ("Payload", response_text); |
| 10713 | } |
| 10714 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10715 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10716 | HttpRequestInfo request; |
| 10717 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10718 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10719 | request.traffic_annotation = |
| 10720 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10721 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10722 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10723 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10724 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10725 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10726 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10727 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10728 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10729 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10730 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10731 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 10732 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10733 | |
| 10734 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10735 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10736 | base::size(write_buffer)), |
| 10737 | MockWrite("GET / HTTP/1.1\r\n" |
| 10738 | "Host: www.example.org\r\n" |
| 10739 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10740 | |
| 10741 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10742 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 10743 | base::size(read_buffer)), |
| 10744 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10745 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10746 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10747 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10748 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10749 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10750 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10751 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10752 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10753 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10754 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10755 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10756 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10757 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10758 | |
| 10759 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10760 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10761 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10762 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10763 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10764 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10765 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 10766 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10767 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10768 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10769 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10770 | |
| 10771 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10772 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10773 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10774 | EXPECT_EQ("Payload", response_text); |
| 10775 | } |
| 10776 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10777 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10778 | HttpRequestInfo request; |
| 10779 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10780 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10781 | request.traffic_annotation = |
| 10782 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10783 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10784 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10785 | "socks4://myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10786 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10787 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10788 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10789 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10790 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10791 | |
| 10792 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 10793 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10794 | |
| 10795 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10796 | MockWrite(ASYNC, write_buffer, base::size(write_buffer)), |
| 10797 | MockWrite("GET / HTTP/1.1\r\n" |
| 10798 | "Host: www.example.org\r\n" |
| 10799 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10800 | |
| 10801 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10802 | MockRead(ASYNC, read_buffer, base::size(read_buffer)), |
| 10803 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10804 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10805 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10806 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10807 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10808 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10809 | |
| 10810 | TestCompletionCallback callback; |
| 10811 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10812 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10813 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10814 | |
| 10815 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10816 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10817 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10818 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10819 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10820 | |
| 10821 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10822 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10823 | TestLoadTimingNotReused(load_timing_info, |
| 10824 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10825 | |
| 10826 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10827 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10828 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10829 | EXPECT_EQ("Payload", response_text); |
| 10830 | } |
| 10831 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10832 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10833 | HttpRequestInfo request; |
| 10834 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10835 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10836 | request.traffic_annotation = |
| 10837 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10838 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10839 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10840 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10841 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10842 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10843 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10844 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10845 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10846 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10847 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10848 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 10849 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10850 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10851 | 0x05, // Version |
| 10852 | 0x01, // Command (CONNECT) |
| 10853 | 0x00, // Reserved. |
| 10854 | 0x03, // Address type (DOMAINNAME). |
| 10855 | 0x0F, // Length of domain (15) |
| 10856 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 10857 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10858 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10859 | const char kSOCKS5OkResponse[] = |
| 10860 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 10861 | |
| 10862 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10863 | MockWrite(ASYNC, kSOCKS5GreetRequest, base::size(kSOCKS5GreetRequest)), |
| 10864 | MockWrite(ASYNC, kSOCKS5OkRequest, base::size(kSOCKS5OkRequest)), |
| 10865 | MockWrite("GET / HTTP/1.1\r\n" |
| 10866 | "Host: www.example.org\r\n" |
| 10867 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10868 | |
| 10869 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10870 | MockRead(ASYNC, kSOCKS5GreetResponse, base::size(kSOCKS5GreetResponse)), |
| 10871 | MockRead(ASYNC, kSOCKS5OkResponse, base::size(kSOCKS5OkResponse)), |
| 10872 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10873 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10874 | MockRead("Payload"), |
| 10875 | MockRead(SYNCHRONOUS, OK)}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10876 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10877 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10878 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10879 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10880 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10881 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10882 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10883 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10884 | |
| 10885 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10886 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10887 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10888 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10889 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10890 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10891 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10892 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10893 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10894 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10895 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10896 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10897 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10898 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10899 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10900 | EXPECT_EQ("Payload", response_text); |
| 10901 | } |
| 10902 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10903 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10904 | HttpRequestInfo request; |
| 10905 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10906 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10907 | request.traffic_annotation = |
| 10908 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10909 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10910 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10911 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10912 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10913 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10914 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10915 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10916 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10917 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10918 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10919 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 10920 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10921 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10922 | 0x05, // Version |
| 10923 | 0x01, // Command (CONNECT) |
| 10924 | 0x00, // Reserved. |
| 10925 | 0x03, // Address type (DOMAINNAME). |
| 10926 | 0x0F, // Length of domain (15) |
| 10927 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 10928 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10929 | }; |
| 10930 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10931 | const char kSOCKS5OkResponse[] = |
| 10932 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 10933 | |
| 10934 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10935 | MockWrite(ASYNC, kSOCKS5GreetRequest, base::size(kSOCKS5GreetRequest)), |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10936 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10937 | base::size(kSOCKS5OkRequest)), |
| 10938 | MockWrite("GET / HTTP/1.1\r\n" |
| 10939 | "Host: www.example.org\r\n" |
| 10940 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10941 | |
| 10942 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10943 | MockRead(ASYNC, kSOCKS5GreetResponse, base::size(kSOCKS5GreetResponse)), |
| 10944 | MockRead(ASYNC, kSOCKS5OkResponse, base::size(kSOCKS5OkResponse)), |
| 10945 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10946 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10947 | MockRead("Payload"), |
| 10948 | MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10949 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10950 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10951 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10952 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10953 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10954 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10955 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10956 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10957 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10958 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10959 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10960 | |
| 10961 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10962 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10963 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10964 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10965 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10966 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10967 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10968 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10969 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10970 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10971 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 10972 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10973 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10974 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10975 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10976 | EXPECT_EQ("Payload", response_text); |
| 10977 | } |
| 10978 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10979 | namespace { |
| 10980 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10981 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10982 | |
| 10983 | struct GroupNameTest { |
| 10984 | std::string proxy_server; |
| 10985 | std::string url; |
| 10986 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10987 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10988 | }; |
| 10989 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10990 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10991 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10992 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10993 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10994 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10995 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10996 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10997 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10998 | http_server_properties->SetHttp2AlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 10999 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11000 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11001 | |
| 11002 | return session; |
| 11003 | } |
| 11004 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11005 | int GroupNameTransactionHelper(const std::string& url, |
| 11006 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11007 | HttpRequestInfo request; |
| 11008 | request.method = "GET"; |
| 11009 | request.url = GURL(url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11010 | request.traffic_annotation = |
| 11011 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11012 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11013 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11014 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11015 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11016 | |
| 11017 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11018 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11019 | } |
| 11020 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11021 | } // namespace |
| 11022 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11023 | TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11024 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11025 | { |
| 11026 | "", // unused |
| 11027 | "http://www.example.org/direct", |
| 11028 | "www.example.org:80", |
| 11029 | false, |
| 11030 | }, |
| 11031 | { |
| 11032 | "", // unused |
| 11033 | "http://[2001:1418:13:1::25]/direct", |
| 11034 | "[2001:1418:13:1::25]:80", |
| 11035 | false, |
| 11036 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11037 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11038 | // SSL Tests |
| 11039 | { |
| 11040 | "", // unused |
| 11041 | "https://www.example.org/direct_ssl", |
| 11042 | "ssl/www.example.org:443", |
| 11043 | true, |
| 11044 | }, |
| 11045 | { |
| 11046 | "", // unused |
| 11047 | "https://[2001:1418:13:1::25]/direct", |
| 11048 | "ssl/[2001:1418:13:1::25]:443", |
| 11049 | true, |
| 11050 | }, |
| 11051 | { |
| 11052 | "", // unused |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 11053 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11054 | "ssl/host.with.alternate:443", |
| 11055 | true, |
| 11056 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11057 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11058 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11059 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11060 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11061 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11062 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11063 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 11064 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11065 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11066 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11067 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11068 | new CaptureGroupNameTransportSocketPool(nullptr, nullptr); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 11069 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11070 | new CaptureGroupNameSSLSocketPool(nullptr, nullptr); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11071 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 11072 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 11073 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11074 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11075 | |
| 11076 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11077 | GroupNameTransactionHelper(tests[i].url, session.get())); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 11078 | if (tests[i].ssl) { |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 11079 | EXPECT_EQ(tests[i].expected_group_name, |
| 11080 | ssl_conn_pool->last_group_name_received()); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 11081 | } else { |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 11082 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11083 | transport_conn_pool->last_group_name_received()); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 11084 | } |
| 11085 | // When SSL proxy is in use, socket must be requested from |ssl_conn_pool|. |
| 11086 | EXPECT_EQ(tests[i].ssl, ssl_conn_pool->socket_requested()); |
| 11087 | // When SSL proxy is not in use, socket must be requested from |
| 11088 | // |transport_conn_pool|. |
| 11089 | EXPECT_EQ(!tests[i].ssl, transport_conn_pool->socket_requested()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11090 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11091 | } |
| 11092 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11093 | TEST_F(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11094 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11095 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 11096 | "http_proxy", "http://www.example.org/http_proxy_normal", |
| 11097 | "http_proxy/www.example.org:80", false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11098 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11099 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11100 | // SSL Tests |
| 11101 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 11102 | "http_proxy", "https://www.example.org/http_connect_ssl", |
| 11103 | "http_proxy/ssl/www.example.org:443", true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11104 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 11105 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11106 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 11107 | "http_proxy", "https://host.with.alternate/direct", |
| 11108 | "http_proxy/ssl/host.with.alternate:443", true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11109 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 11110 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11111 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 11112 | "http_proxy", "ftp://ftp.google.com/http_proxy_normal", |
| 11113 | "http_proxy/ftp/ftp.google.com:21", false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11114 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11115 | }; |
| 11116 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11117 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11118 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11119 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11120 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11121 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 11122 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11123 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11124 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11125 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11126 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 11127 | HostPortPair("http_proxy", 80)); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 11128 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 11129 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 11130 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 11131 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11132 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 11133 | mock_pool_manager->SetSocketPoolForHTTPProxy( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11134 | proxy_server, base::WrapUnique(http_proxy_pool)); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 11135 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11136 | proxy_server, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11137 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11138 | |
| 11139 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11140 | GroupNameTransactionHelper(tests[i].url, session.get())); |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11141 | if (tests[i].ssl) { |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 11142 | EXPECT_EQ(tests[i].expected_group_name, |
| 11143 | ssl_conn_pool->last_group_name_received()); |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11144 | } else { |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 11145 | EXPECT_EQ(tests[i].expected_group_name, |
| 11146 | http_proxy_pool->last_group_name_received()); |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11147 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11148 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11149 | } |
| 11150 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11151 | TEST_F(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11152 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11153 | { |
| 11154 | "socks4://socks_proxy:1080", |
| 11155 | "http://www.example.org/socks4_direct", |
| 11156 | "socks4/www.example.org:80", |
| 11157 | false, |
| 11158 | }, |
| 11159 | { |
| 11160 | "socks5://socks_proxy:1080", |
| 11161 | "http://www.example.org/socks5_direct", |
| 11162 | "socks5/www.example.org:80", |
| 11163 | false, |
| 11164 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11165 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11166 | // SSL Tests |
| 11167 | { |
| 11168 | "socks4://socks_proxy:1080", |
| 11169 | "https://www.example.org/socks4_ssl", |
| 11170 | "socks4/ssl/www.example.org:443", |
| 11171 | true, |
| 11172 | }, |
| 11173 | { |
| 11174 | "socks5://socks_proxy:1080", |
| 11175 | "https://www.example.org/socks5_ssl", |
| 11176 | "socks5/ssl/www.example.org:443", |
| 11177 | true, |
| 11178 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 11179 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11180 | { |
| 11181 | "socks4://socks_proxy:1080", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 11182 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11183 | "socks4/ssl/host.with.alternate:443", |
| 11184 | true, |
| 11185 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11186 | }; |
| 11187 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11188 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11189 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11190 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11191 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11192 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 11193 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 11194 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11195 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11196 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11197 | ProxyServer proxy_server( |
| 11198 | ProxyServer::FromURI(tests[i].proxy_server, ProxyServer::SCHEME_HTTP)); |
| 11199 | ASSERT_TRUE(proxy_server.is_valid()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 11200 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 11201 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 11202 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 11203 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11204 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 11205 | mock_pool_manager->SetSocketPoolForSOCKSProxy( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11206 | proxy_server, base::WrapUnique(socks_conn_pool)); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 11207 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11208 | proxy_server, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11209 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11210 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11211 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11212 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11213 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11214 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 11215 | if (tests[i].ssl) |
| 11216 | EXPECT_EQ(tests[i].expected_group_name, |
| 11217 | ssl_conn_pool->last_group_name_received()); |
| 11218 | else |
| 11219 | EXPECT_EQ(tests[i].expected_group_name, |
| 11220 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11221 | } |
| 11222 | } |
| 11223 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11224 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11225 | HttpRequestInfo request; |
| 11226 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11227 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11228 | request.traffic_annotation = |
| 11229 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11230 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11231 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 11232 | "myproxy:70;foobar:80", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 11233 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 11234 | // This simulates failure resolving all hostnames; that means we will fail |
| 11235 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11236 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 11237 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11238 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11239 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11240 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11241 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11242 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11243 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11244 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11245 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11246 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11247 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11248 | } |
| 11249 | |
Miriam Gershenson | 2a01b16 | 2018-03-22 22:54:47 | [diff] [blame] | 11250 | // LOAD_BYPASS_CACHE should trigger the host cache bypass. |
| 11251 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11252 | // Issue a request, asking to bypass the cache(s). |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 11253 | HttpRequestInfo request_info; |
| 11254 | request_info.method = "GET"; |
Miriam Gershenson | 2a01b16 | 2018-03-22 22:54:47 | [diff] [blame] | 11255 | request_info.load_flags = LOAD_BYPASS_CACHE; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 11256 | request_info.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11257 | request_info.traffic_annotation = |
| 11258 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11259 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 11260 | // Select a host resolver that does caching. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11261 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 11262 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11263 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11264 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11265 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11266 | // 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] | 11267 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 11268 | TestCompletionCallback callback; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 11269 | std::unique_ptr<HostResolver::Request> request1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11270 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11271 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 11272 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request1, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11273 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11274 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 11275 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11276 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11277 | |
| 11278 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 11279 | // and confirming it completes synchronously. |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 11280 | std::unique_ptr<HostResolver::Request> request2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11281 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11282 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 11283 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request2, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11284 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11285 | ASSERT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11286 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11287 | // 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] | 11288 | // we can tell if the next lookup hit the cache, or the "network". |
| 11289 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11290 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11291 | |
| 11292 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 11293 | // 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] | 11294 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11295 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11296 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11297 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11298 | // Run the request. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11299 | rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11300 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11301 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11302 | |
| 11303 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11304 | // "www.example.org". |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11305 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11306 | } |
| 11307 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11308 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11309 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11310 | HttpRequestInfo request; |
| 11311 | request.method = "GET"; |
| 11312 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11313 | request.traffic_annotation = |
| 11314 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11315 | |
| 11316 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11317 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11318 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11319 | StaticSocketDataProvider data(base::span<MockRead>(), write_failure); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11320 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11321 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11322 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11323 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11324 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11325 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11326 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11327 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11328 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11329 | |
| 11330 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11331 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11332 | |
| 11333 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11334 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11335 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11336 | } |
| 11337 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11338 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11339 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11340 | HttpRequestInfo request; |
| 11341 | request.method = "GET"; |
| 11342 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11343 | request.traffic_annotation = |
| 11344 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11345 | |
| 11346 | MockRead data_reads[] = { |
| 11347 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11348 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11349 | }; |
| 11350 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11351 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11352 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11353 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11354 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11355 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11356 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11357 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11358 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11359 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11360 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11361 | |
| 11362 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11363 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11364 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11365 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11366 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11367 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11368 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11369 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 11370 | |
| 11371 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11372 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11373 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11374 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11375 | |
| 11376 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11377 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11378 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11379 | } |
| 11380 | |
| 11381 | // Make sure that a dropped connection while draining the body for auth |
| 11382 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11383 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11384 | HttpRequestInfo request; |
| 11385 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11386 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11387 | request.traffic_annotation = |
| 11388 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11389 | |
| 11390 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11391 | MockWrite( |
| 11392 | "GET / HTTP/1.1\r\n" |
| 11393 | "Host: www.example.org\r\n" |
| 11394 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11395 | }; |
| 11396 | |
| 11397 | MockRead data_reads1[] = { |
| 11398 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 11399 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 11400 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11401 | MockRead("Content-Length: 14\r\n\r\n"), |
| 11402 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11403 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11404 | }; |
| 11405 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11406 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11407 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11408 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11409 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11410 | // be issuing -- the final header line contains the credentials. |
| 11411 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11412 | MockWrite( |
| 11413 | "GET / HTTP/1.1\r\n" |
| 11414 | "Host: www.example.org\r\n" |
| 11415 | "Connection: keep-alive\r\n" |
| 11416 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11417 | }; |
| 11418 | |
| 11419 | // Lastly, the server responds with the actual content. |
| 11420 | MockRead data_reads2[] = { |
| 11421 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11422 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11423 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11424 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11425 | }; |
| 11426 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11427 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11428 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11429 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11430 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11431 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11432 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11433 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11434 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11435 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11436 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11437 | |
| 11438 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11439 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11440 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11441 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11442 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11443 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11444 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11445 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11446 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11447 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11448 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11449 | |
| 11450 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11451 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11452 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11453 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11454 | ASSERT_TRUE(response); |
| 11455 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11456 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 11457 | } |
| 11458 | |
| 11459 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11460 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11461 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 11462 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11463 | |
| 11464 | HttpRequestInfo request; |
| 11465 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11466 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11467 | request.traffic_annotation = |
| 11468 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11469 | |
| 11470 | MockRead proxy_reads[] = { |
| 11471 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11472 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11473 | }; |
| 11474 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11475 | StaticSocketDataProvider data(proxy_reads, base::span<MockWrite>()); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11476 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11477 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11478 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11479 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11480 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11481 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11482 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11483 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11484 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11485 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11486 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11487 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11488 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11489 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11490 | |
| 11491 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11492 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11493 | } |
| 11494 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11495 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11496 | HttpRequestInfo request; |
| 11497 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11498 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11499 | request.traffic_annotation = |
| 11500 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11501 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11502 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11503 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11504 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11505 | MockRead data_reads[] = { |
| 11506 | 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] | 11507 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11508 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11509 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11510 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11511 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11512 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11513 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11514 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11515 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11516 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11517 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11518 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11519 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11520 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11521 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11522 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11523 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11524 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 11525 | |
| 11526 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11527 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11528 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11529 | } |
| 11530 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11531 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 11532 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 11533 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11534 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 11535 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 11536 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11537 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11538 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11539 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11540 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 11541 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11542 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11543 | |
| 11544 | HttpRequestInfo request; |
| 11545 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11546 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11547 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11548 | request.traffic_annotation = |
| 11549 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11550 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11551 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11552 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11553 | |
| 11554 | MockRead data_reads[] = { |
| 11555 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 11556 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11557 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11558 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11559 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11560 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11561 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11562 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11563 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11564 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11565 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11566 | |
| 11567 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11568 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11569 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11570 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11571 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11572 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 11573 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11574 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 11575 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11576 | } |
| 11577 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11578 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 11579 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 11580 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11581 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 11582 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 11583 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 11584 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 11585 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11586 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11587 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11588 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11589 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 11590 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11591 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11592 | |
| 11593 | HttpRequestInfo request; |
| 11594 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11595 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11596 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11597 | request.traffic_annotation = |
| 11598 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11599 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 11600 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11601 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11602 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11603 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11604 | StaticSocketDataProvider data; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11605 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11606 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11607 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11608 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11609 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11610 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11611 | |
| 11612 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11613 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11614 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 11615 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11616 | } |
| 11617 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11618 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11619 | class FakeUploadElementReader : public UploadElementReader { |
| 11620 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 11621 | FakeUploadElementReader() = default; |
| 11622 | ~FakeUploadElementReader() override = default; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11623 | |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11624 | CompletionOnceCallback TakeCallback() { return std::move(callback_); } |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11625 | |
| 11626 | // UploadElementReader overrides: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11627 | int Init(CompletionOnceCallback callback) override { |
| 11628 | callback_ = std::move(callback); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11629 | return ERR_IO_PENDING; |
| 11630 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11631 | uint64_t GetContentLength() const override { return 0; } |
| 11632 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11633 | int Read(IOBuffer* buf, |
| 11634 | int buf_length, |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11635 | CompletionOnceCallback callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11636 | return ERR_FAILED; |
| 11637 | } |
| 11638 | |
| 11639 | private: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11640 | CompletionOnceCallback callback_; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11641 | }; |
| 11642 | |
| 11643 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11644 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 11645 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11646 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11647 | |
| 11648 | HttpRequestInfo request; |
| 11649 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11650 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11651 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11652 | request.traffic_annotation = |
| 11653 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11654 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11655 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11656 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11657 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11658 | |
| 11659 | StaticSocketDataProvider data; |
| 11660 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11661 | |
| 11662 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11663 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11664 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 11665 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11666 | |
| 11667 | // Transaction is pending on request body initialization. |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11668 | CompletionOnceCallback init_callback = fake_reader->TakeCallback(); |
| 11669 | ASSERT_FALSE(init_callback.is_null()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11670 | |
| 11671 | // Return Init()'s result after the transaction gets destroyed. |
| 11672 | trans.reset(); |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11673 | std::move(init_callback).Run(OK); // Should not crash. |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11674 | } |
| 11675 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11676 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11677 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11678 | HttpRequestInfo request; |
| 11679 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11680 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11681 | request.traffic_annotation = |
| 11682 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11683 | |
| 11684 | // First transaction will request a resource and receive a Basic challenge |
| 11685 | // with realm="first_realm". |
| 11686 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11687 | MockWrite( |
| 11688 | "GET / HTTP/1.1\r\n" |
| 11689 | "Host: www.example.org\r\n" |
| 11690 | "Connection: keep-alive\r\n" |
| 11691 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11692 | }; |
| 11693 | MockRead data_reads1[] = { |
| 11694 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11695 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 11696 | "\r\n"), |
| 11697 | }; |
| 11698 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11699 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11700 | // for first_realm. The server will reject and provide a challenge with |
| 11701 | // second_realm. |
| 11702 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11703 | MockWrite( |
| 11704 | "GET / HTTP/1.1\r\n" |
| 11705 | "Host: www.example.org\r\n" |
| 11706 | "Connection: keep-alive\r\n" |
| 11707 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 11708 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11709 | }; |
| 11710 | MockRead data_reads2[] = { |
| 11711 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11712 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 11713 | "\r\n"), |
| 11714 | }; |
| 11715 | |
| 11716 | // This again fails, and goes back to first_realm. Make sure that the |
| 11717 | // entry is removed from cache. |
| 11718 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11719 | MockWrite( |
| 11720 | "GET / HTTP/1.1\r\n" |
| 11721 | "Host: www.example.org\r\n" |
| 11722 | "Connection: keep-alive\r\n" |
| 11723 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 11724 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11725 | }; |
| 11726 | MockRead data_reads3[] = { |
| 11727 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11728 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 11729 | "\r\n"), |
| 11730 | }; |
| 11731 | |
| 11732 | // Try one last time (with the correct password) and get the resource. |
| 11733 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11734 | MockWrite( |
| 11735 | "GET / HTTP/1.1\r\n" |
| 11736 | "Host: www.example.org\r\n" |
| 11737 | "Connection: keep-alive\r\n" |
| 11738 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 11739 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11740 | }; |
| 11741 | MockRead data_reads4[] = { |
| 11742 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11743 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11744 | "Content-Length: 5\r\n" |
| 11745 | "\r\n" |
| 11746 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11747 | }; |
| 11748 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11749 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 11750 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 11751 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
| 11752 | StaticSocketDataProvider data4(data_reads4, data_writes4); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11753 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 11754 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 11755 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 11756 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11757 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11758 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11759 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11760 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11761 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11762 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11763 | // Issue the first request with Authorize headers. There should be a |
| 11764 | // password prompt for first_realm waiting to be filled in after the |
| 11765 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11766 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11767 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11768 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11769 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11770 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11771 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11772 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11773 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11774 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11775 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11776 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11777 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11778 | |
| 11779 | // Issue the second request with an incorrect password. There should be a |
| 11780 | // password prompt for second_realm waiting to be filled in after the |
| 11781 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11782 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11783 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 11784 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11785 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11786 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11787 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11788 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11789 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11790 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11791 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11792 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11793 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11794 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11795 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11796 | |
| 11797 | // Issue the third request with another incorrect password. There should be |
| 11798 | // a password prompt for first_realm waiting to be filled in. If the password |
| 11799 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 11800 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11801 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11802 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 11803 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11804 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11805 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11806 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11807 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11808 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11809 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11810 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11811 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11812 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11813 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11814 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11815 | |
| 11816 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11817 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11818 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 11819 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11820 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11821 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11822 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11823 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11824 | ASSERT_TRUE(response); |
| 11825 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11826 | } |
| 11827 | |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11828 | // Regression test for https://crbug.com/754395. |
| 11829 | TEST_F(HttpNetworkTransactionTest, IgnoreAltSvcWithInvalidCert) { |
| 11830 | MockRead data_reads[] = { |
| 11831 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11832 | MockRead(kAlternativeServiceHttpHeader), |
| 11833 | MockRead("\r\n"), |
| 11834 | MockRead("hello world"), |
| 11835 | MockRead(SYNCHRONOUS, OK), |
| 11836 | }; |
| 11837 | |
| 11838 | HttpRequestInfo request; |
| 11839 | request.method = "GET"; |
| 11840 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11841 | request.traffic_annotation = |
| 11842 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11843 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11844 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11845 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11846 | |
| 11847 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11848 | ssl.ssl_info.cert = |
| 11849 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11850 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 11851 | ssl.ssl_info.cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11852 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11853 | |
| 11854 | TestCompletionCallback callback; |
| 11855 | |
| 11856 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11857 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11858 | |
| 11859 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 11860 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11861 | |
| 11862 | url::SchemeHostPort test_server(request.url); |
| 11863 | HttpServerProperties* http_server_properties = |
| 11864 | session->http_server_properties(); |
| 11865 | EXPECT_TRUE( |
| 11866 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 11867 | |
| 11868 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 11869 | |
| 11870 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11871 | ASSERT_TRUE(response); |
| 11872 | ASSERT_TRUE(response->headers); |
| 11873 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11874 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 11875 | EXPECT_FALSE(response->was_alpn_negotiated); |
| 11876 | |
| 11877 | std::string response_data; |
| 11878 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 11879 | EXPECT_EQ("hello world", response_data); |
| 11880 | |
| 11881 | EXPECT_TRUE( |
| 11882 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 11883 | } |
| 11884 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11885 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11886 | MockRead data_reads[] = { |
| 11887 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11888 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11889 | MockRead("\r\n"), |
| 11890 | MockRead("hello world"), |
| 11891 | MockRead(SYNCHRONOUS, OK), |
| 11892 | }; |
| 11893 | |
| 11894 | HttpRequestInfo request; |
| 11895 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11896 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11897 | request.traffic_annotation = |
| 11898 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11899 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11900 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11901 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11902 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11903 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11904 | ssl.ssl_info.cert = |
| 11905 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11906 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11907 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11908 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11909 | TestCompletionCallback callback; |
| 11910 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11911 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11912 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11913 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11914 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11915 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11916 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11917 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11918 | HttpServerProperties* http_server_properties = |
| 11919 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11920 | EXPECT_TRUE( |
| 11921 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11922 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11923 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11924 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11925 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11926 | ASSERT_TRUE(response); |
| 11927 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11928 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11929 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11930 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11931 | |
| 11932 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11933 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11934 | EXPECT_EQ("hello world", response_data); |
| 11935 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11936 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 11937 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 11938 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 11939 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 11940 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11941 | alternative_service_info_vector[0].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11942 | } |
| 11943 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11944 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11945 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11946 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11947 | MockRead data_reads[] = { |
| 11948 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11949 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11950 | MockRead("\r\n"), |
| 11951 | MockRead("hello world"), |
| 11952 | MockRead(SYNCHRONOUS, OK), |
| 11953 | }; |
| 11954 | |
| 11955 | HttpRequestInfo request; |
| 11956 | request.method = "GET"; |
| 11957 | request.url = GURL("http://www.example.org/"); |
| 11958 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11959 | request.traffic_annotation = |
| 11960 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11961 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11962 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11963 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11964 | |
| 11965 | TestCompletionCallback callback; |
| 11966 | |
| 11967 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11968 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11969 | |
| 11970 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11971 | HttpServerProperties* http_server_properties = |
| 11972 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11973 | EXPECT_TRUE( |
| 11974 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11975 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11976 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11977 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11978 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11979 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11980 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11981 | ASSERT_TRUE(response); |
| 11982 | ASSERT_TRUE(response->headers); |
| 11983 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11984 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11985 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11986 | |
| 11987 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11988 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11989 | EXPECT_EQ("hello world", response_data); |
| 11990 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11991 | EXPECT_TRUE( |
| 11992 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11993 | } |
| 11994 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 11995 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11996 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11997 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11998 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 11999 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12000 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12001 | HttpRequestInfo request; |
| 12002 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12003 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12004 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12005 | request.traffic_annotation = |
| 12006 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12007 | |
| 12008 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12009 | StaticSocketDataProvider first_data; |
| 12010 | first_data.set_connect_data(mock_connect); |
| 12011 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12012 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12013 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12014 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12015 | |
| 12016 | MockRead data_reads[] = { |
| 12017 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 12018 | MockRead(ASYNC, OK), |
| 12019 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12020 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12021 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 12022 | |
| 12023 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12024 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12025 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12026 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12027 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 12028 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12029 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12030 | http_server_properties->SetHttp2AlternativeService( |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12031 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 12032 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12033 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12034 | TestCompletionCallback callback; |
| 12035 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12036 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12037 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12038 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12039 | } |
| 12040 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12041 | // Regression test for https://crbug.com/615497: |
| 12042 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12043 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12044 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12045 | HttpRequestInfo request; |
| 12046 | request.method = "GET"; |
| 12047 | request.url = GURL("http://www.example.org/"); |
| 12048 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12049 | request.traffic_annotation = |
| 12050 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12051 | |
| 12052 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12053 | StaticSocketDataProvider first_data; |
| 12054 | first_data.set_connect_data(mock_connect); |
| 12055 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 12056 | |
| 12057 | MockRead data_reads[] = { |
| 12058 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 12059 | MockRead(ASYNC, OK), |
| 12060 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12061 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12062 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 12063 | |
| 12064 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12065 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12066 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12067 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12068 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12069 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12070 | http_server_properties->SetHttp2AlternativeService( |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12071 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 12072 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12073 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12074 | TestCompletionCallback callback; |
| 12075 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12076 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12077 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12078 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12079 | } |
| 12080 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12081 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12082 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12083 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12084 | HttpServerProperties* http_server_properties = |
| 12085 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12086 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12087 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12088 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12089 | http_server_properties->SetQuicAlternativeService( |
| 12090 | test_server, alternative_service, expiration, |
| 12091 | session->params().quic_supported_versions); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12092 | EXPECT_EQ( |
| 12093 | 1u, |
| 12094 | http_server_properties->GetAlternativeServiceInfos(test_server).size()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12095 | |
| 12096 | // Send a clear header. |
| 12097 | MockRead data_reads[] = { |
| 12098 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12099 | MockRead("Alt-Svc: clear\r\n"), |
| 12100 | MockRead("\r\n"), |
| 12101 | MockRead("hello world"), |
| 12102 | MockRead(SYNCHRONOUS, OK), |
| 12103 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12104 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12105 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12106 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12107 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12108 | ssl.ssl_info.cert = |
| 12109 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12110 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12111 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12112 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12113 | HttpRequestInfo request; |
| 12114 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12115 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12116 | request.traffic_annotation = |
| 12117 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12118 | |
| 12119 | TestCompletionCallback callback; |
| 12120 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12121 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12122 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12123 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12124 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12125 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12126 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12127 | ASSERT_TRUE(response); |
| 12128 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12129 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12130 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12131 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12132 | |
| 12133 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12134 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12135 | EXPECT_EQ("hello world", response_data); |
| 12136 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12137 | EXPECT_TRUE( |
| 12138 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12139 | } |
| 12140 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12141 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12142 | MockRead data_reads[] = { |
| 12143 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12144 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 12145 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12146 | MockRead("hello world"), |
| 12147 | MockRead(SYNCHRONOUS, OK), |
| 12148 | }; |
| 12149 | |
| 12150 | HttpRequestInfo request; |
| 12151 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12152 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12153 | request.traffic_annotation = |
| 12154 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12155 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12156 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12157 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12158 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12159 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12160 | ssl.ssl_info.cert = |
| 12161 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12162 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12163 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12164 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12165 | TestCompletionCallback callback; |
| 12166 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12167 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12168 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12169 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12170 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12171 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12172 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12173 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12174 | HttpServerProperties* http_server_properties = |
| 12175 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12176 | EXPECT_TRUE( |
| 12177 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12178 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12179 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12180 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12181 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12182 | ASSERT_TRUE(response); |
| 12183 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12184 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12185 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12186 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12187 | |
| 12188 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12189 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12190 | EXPECT_EQ("hello world", response_data); |
| 12191 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12192 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 12193 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 12194 | ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 12195 | |
| 12196 | AlternativeService alternative_service(kProtoHTTP2, "www.example.com", 443); |
| 12197 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12198 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12199 | AlternativeService alternative_service_2(kProtoHTTP2, "www.example.org", |
| 12200 | 1234); |
| 12201 | EXPECT_EQ(alternative_service_2, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12202 | alternative_service_info_vector[1].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12203 | } |
| 12204 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12205 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12206 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12207 | HostPortPair alternative("alternative.example.org", 443); |
| 12208 | std::string origin_url = "https://origin.example.org:443"; |
| 12209 | std::string alternative_url = "https://alternative.example.org:443"; |
| 12210 | |
| 12211 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 12212 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12213 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12214 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12215 | |
| 12216 | // HTTP/1.1 data for request. |
| 12217 | MockWrite http_writes[] = { |
| 12218 | MockWrite("GET / HTTP/1.1\r\n" |
| 12219 | "Host: alternative.example.org\r\n" |
| 12220 | "Connection: keep-alive\r\n\r\n"), |
| 12221 | }; |
| 12222 | |
| 12223 | MockRead http_reads[] = { |
| 12224 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12225 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12226 | "Content-Length: 40\r\n\r\n" |
| 12227 | "first HTTP/1.1 response from alternative"), |
| 12228 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12229 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12230 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12231 | |
| 12232 | StaticSocketDataProvider data_refused; |
| 12233 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12234 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12235 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12236 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12237 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12238 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12239 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12240 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12241 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12242 | http_server_properties->SetQuicAlternativeService( |
| 12243 | server, alternative_service, expiration, |
| 12244 | HttpNetworkSession::Params().quic_supported_versions); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12245 | // Mark the QUIC alternative service as broken. |
| 12246 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 12247 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12248 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 12249 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12250 | request.method = "GET"; |
| 12251 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12252 | request.traffic_annotation = |
| 12253 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 12254 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12255 | TestCompletionCallback callback; |
| 12256 | NetErrorDetails details; |
| 12257 | EXPECT_FALSE(details.quic_broken); |
| 12258 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12259 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12260 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12261 | EXPECT_TRUE(details.quic_broken); |
| 12262 | } |
| 12263 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12264 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12265 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12266 | HostPortPair alternative1("alternative1.example.org", 443); |
| 12267 | HostPortPair alternative2("alternative2.example.org", 443); |
| 12268 | std::string origin_url = "https://origin.example.org:443"; |
| 12269 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 12270 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 12271 | |
| 12272 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 12273 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12274 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12275 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12276 | |
| 12277 | // HTTP/1.1 data for request. |
| 12278 | MockWrite http_writes[] = { |
| 12279 | MockWrite("GET / HTTP/1.1\r\n" |
| 12280 | "Host: alternative1.example.org\r\n" |
| 12281 | "Connection: keep-alive\r\n\r\n"), |
| 12282 | }; |
| 12283 | |
| 12284 | MockRead http_reads[] = { |
| 12285 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12286 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12287 | "Content-Length: 40\r\n\r\n" |
| 12288 | "first HTTP/1.1 response from alternative1"), |
| 12289 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12290 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12291 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12292 | |
| 12293 | StaticSocketDataProvider data_refused; |
| 12294 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12295 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12296 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12297 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12298 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12299 | session->http_server_properties(); |
| 12300 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12301 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12302 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 12303 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 12304 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12305 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12306 | alternative_service_info_vector.push_back( |
| 12307 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 12308 | alternative_service1, expiration, |
| 12309 | session->params().quic_supported_versions)); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12310 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12311 | alternative_service_info_vector.push_back( |
| 12312 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 12313 | alternative_service2, expiration, |
| 12314 | session->params().quic_supported_versions)); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12315 | |
| 12316 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12317 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12318 | |
| 12319 | // Mark one of the QUIC alternative service as broken. |
| 12320 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12321 | EXPECT_EQ(2u, |
| 12322 | http_server_properties->GetAlternativeServiceInfos(server).size()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12323 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12324 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 12325 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12326 | request.method = "GET"; |
| 12327 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12328 | request.traffic_annotation = |
| 12329 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 12330 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12331 | TestCompletionCallback callback; |
| 12332 | NetErrorDetails details; |
| 12333 | EXPECT_FALSE(details.quic_broken); |
| 12334 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12335 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12336 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12337 | EXPECT_FALSE(details.quic_broken); |
| 12338 | } |
| 12339 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12340 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12341 | HttpRequestInfo request; |
| 12342 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12343 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12344 | request.traffic_annotation = |
| 12345 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12346 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12347 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12348 | StaticSocketDataProvider first_data; |
| 12349 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12350 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12351 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12352 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12353 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12354 | |
| 12355 | MockRead data_reads[] = { |
| 12356 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12357 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12358 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12359 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12360 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12361 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12362 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12363 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12364 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12365 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12366 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12367 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12368 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 12369 | // port 80 (another restricted port). |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12370 | // Port is ignored by MockConnect anyway. |
| 12371 | const AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12372 | 666); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12373 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12374 | http_server_properties->SetHttp2AlternativeService( |
| 12375 | server, alternative_service, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12376 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12377 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12378 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12379 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12380 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12381 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12382 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12383 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12384 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12385 | ASSERT_TRUE(response); |
| 12386 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12387 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12388 | |
| 12389 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12390 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12391 | EXPECT_EQ("hello world", response_data); |
| 12392 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12393 | const AlternativeServiceInfoVector alternative_service_info_vector = |
| 12394 | http_server_properties->GetAlternativeServiceInfos(server); |
| 12395 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 12396 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12397 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12398 | EXPECT_TRUE( |
| 12399 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12400 | } |
| 12401 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12402 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12403 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12404 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12405 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12406 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12407 | HttpRequestInfo restricted_port_request; |
| 12408 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12409 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12410 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12411 | restricted_port_request.traffic_annotation = |
| 12412 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12413 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12414 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12415 | StaticSocketDataProvider first_data; |
| 12416 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12417 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12418 | |
| 12419 | MockRead data_reads[] = { |
| 12420 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12421 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12422 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12423 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12424 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12425 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12426 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12427 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12428 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12429 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12430 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12431 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12432 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12433 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12434 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12435 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12436 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12437 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12438 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12439 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12440 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12441 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12442 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12443 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12444 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12445 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 12446 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12447 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12448 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12449 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12450 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12451 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12452 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 12453 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 12454 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12455 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12456 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12457 | |
| 12458 | HttpRequestInfo restricted_port_request; |
| 12459 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12460 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12461 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12462 | restricted_port_request.traffic_annotation = |
| 12463 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12464 | |
| 12465 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12466 | StaticSocketDataProvider first_data; |
| 12467 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12468 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12469 | |
| 12470 | MockRead data_reads[] = { |
| 12471 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12472 | MockRead("hello world"), |
| 12473 | MockRead(ASYNC, OK), |
| 12474 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12475 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12476 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12477 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12478 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12479 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12480 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12481 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12482 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12483 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12484 | session->http_server_properties(); |
| 12485 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12486 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12487 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12488 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12489 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12490 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12491 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12492 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12493 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12494 | TestCompletionCallback callback; |
| 12495 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12496 | EXPECT_EQ(ERR_IO_PENDING, |
| 12497 | trans.Start(&restricted_port_request, callback.callback(), |
| 12498 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12499 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12500 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12501 | } |
| 12502 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12503 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12504 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12505 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12506 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12507 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12508 | HttpRequestInfo restricted_port_request; |
| 12509 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12510 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12511 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12512 | restricted_port_request.traffic_annotation = |
| 12513 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12514 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12515 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12516 | StaticSocketDataProvider first_data; |
| 12517 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12518 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12519 | |
| 12520 | MockRead data_reads[] = { |
| 12521 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12522 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12523 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12524 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12525 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12526 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12527 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12528 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12529 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12530 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12531 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12532 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12533 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12534 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12535 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12536 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12537 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12538 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12539 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12540 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12541 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12542 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12543 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12544 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12545 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12546 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 12547 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12548 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12549 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12550 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12551 | } |
| 12552 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12553 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12554 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12555 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12556 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12557 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12558 | HttpRequestInfo unrestricted_port_request; |
| 12559 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12560 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12561 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12562 | unrestricted_port_request.traffic_annotation = |
| 12563 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12564 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12565 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12566 | StaticSocketDataProvider first_data; |
| 12567 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12568 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12569 | |
| 12570 | MockRead data_reads[] = { |
| 12571 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12572 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12573 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12574 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12575 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12576 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12577 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12578 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12579 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12580 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12581 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12582 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12583 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12584 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12585 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12586 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12587 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12588 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12589 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12590 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12591 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12592 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12593 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12594 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12595 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12596 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12597 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12598 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12599 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12600 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12601 | } |
| 12602 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12603 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12604 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12605 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12606 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12607 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12608 | HttpRequestInfo unrestricted_port_request; |
| 12609 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12610 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12611 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12612 | unrestricted_port_request.traffic_annotation = |
| 12613 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12614 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12615 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12616 | StaticSocketDataProvider first_data; |
| 12617 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12618 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12619 | |
| 12620 | MockRead data_reads[] = { |
| 12621 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12622 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12623 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12624 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12625 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12626 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12627 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12628 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12629 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12630 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12631 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12632 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12633 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12634 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 12635 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12636 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12637 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12638 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12639 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12640 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12641 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12642 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12643 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12644 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12645 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12646 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12647 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12648 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12649 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12650 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12651 | } |
| 12652 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12653 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
Xida Chen | 9bfe0b6 | 2018-04-24 19:52:21 | [diff] [blame] | 12654 | // to an unsafe port, and that we resume the second HttpStreamFactory::Job once |
| 12655 | // the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12656 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12657 | HttpRequestInfo request; |
| 12658 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12659 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12660 | request.traffic_annotation = |
| 12661 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12662 | |
| 12663 | // The alternate protocol request will error out before we attempt to connect, |
| 12664 | // so only the standard HTTP request will try to connect. |
| 12665 | MockRead data_reads[] = { |
| 12666 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12667 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12668 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12669 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12670 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12671 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12672 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12673 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12674 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12675 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12676 | session->http_server_properties(); |
| 12677 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12678 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12679 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12680 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12681 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12682 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12683 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12684 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12685 | TestCompletionCallback callback; |
| 12686 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12687 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12688 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12689 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12690 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12691 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12692 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12693 | ASSERT_TRUE(response); |
| 12694 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12695 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12696 | |
| 12697 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12698 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12699 | EXPECT_EQ("hello world", response_data); |
| 12700 | } |
| 12701 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12702 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12703 | HttpRequestInfo request; |
| 12704 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12705 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12706 | request.traffic_annotation = |
| 12707 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12708 | |
| 12709 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12710 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12711 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12712 | MockRead("\r\n"), |
| 12713 | MockRead("hello world"), |
| 12714 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12715 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12716 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12717 | StaticSocketDataProvider first_transaction(data_reads, |
| 12718 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12719 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12720 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12721 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12722 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12723 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12724 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12725 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12726 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12727 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12728 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12729 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12730 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 12731 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12732 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12733 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12734 | }; |
| 12735 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12736 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12737 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12738 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12739 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12740 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12741 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 12742 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12743 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12744 | &hanging_non_alternate_protocol_socket); |
| 12745 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12746 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12747 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12748 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12749 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12750 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12751 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12752 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12753 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12754 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12755 | |
| 12756 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12757 | ASSERT_TRUE(response); |
| 12758 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12759 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12760 | |
| 12761 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12762 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12763 | EXPECT_EQ("hello world", response_data); |
| 12764 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12765 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12766 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12767 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12768 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12769 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12770 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12771 | |
| 12772 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12773 | ASSERT_TRUE(response); |
| 12774 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12775 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12776 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12777 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12778 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12779 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12780 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12781 | } |
| 12782 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12783 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12784 | HttpRequestInfo request; |
| 12785 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12786 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12787 | request.traffic_annotation = |
| 12788 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12789 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12790 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12791 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12792 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12793 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12794 | MockRead("\r\n"), |
| 12795 | MockRead("hello world"), |
| 12796 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12797 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12798 | }; |
| 12799 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12800 | StaticSocketDataProvider http11_data(data_reads, base::span<MockWrite>()); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12801 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12802 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12803 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12804 | ssl_http11.ssl_info.cert = |
| 12805 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12806 | ASSERT_TRUE(ssl_http11.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12807 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 12808 | |
| 12809 | // Second transaction starts an alternative and a non-alternative Job. |
| 12810 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12811 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12812 | StaticSocketDataProvider hanging_socket1; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12813 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12814 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 12815 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12816 | StaticSocketDataProvider hanging_socket2; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12817 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 12818 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12819 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12820 | // Third transaction starts an alternative and a non-alternative job. |
| 12821 | // The non-alternative job hangs, but the alternative one succeeds. |
| 12822 | // The second transaction, still pending, binds to this socket. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12823 | spdy::SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12824 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12825 | spdy::SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12826 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12827 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12828 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12829 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12830 | spdy::SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 12831 | spdy::SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 12832 | spdy::SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 12833 | spdy::SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12834 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12835 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 12836 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12837 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12838 | }; |
| 12839 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12840 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12841 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12842 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12843 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12844 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12845 | StaticSocketDataProvider hanging_socket3; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12846 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 12847 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12848 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12849 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12850 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12851 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12852 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12853 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12854 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12855 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12856 | |
| 12857 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12858 | ASSERT_TRUE(response); |
| 12859 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12860 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12861 | |
| 12862 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12863 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12864 | EXPECT_EQ("hello world", response_data); |
| 12865 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12866 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12867 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12868 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12869 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12870 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12871 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12872 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12873 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12874 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12875 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12876 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 12877 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12878 | |
| 12879 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12880 | ASSERT_TRUE(response); |
| 12881 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12882 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12883 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12884 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12885 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12886 | EXPECT_EQ("hello!", response_data); |
| 12887 | |
| 12888 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12889 | ASSERT_TRUE(response); |
| 12890 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12891 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12892 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12893 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12894 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12895 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12896 | } |
| 12897 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12898 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
Bence Béky | bcae3709 | 2018-06-12 04:18:53 | [diff] [blame] | 12899 | session_deps_.host_resolver->set_synchronous_mode(true); |
| 12900 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12901 | HttpRequestInfo request; |
| 12902 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12903 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12904 | request.traffic_annotation = |
| 12905 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12906 | |
| 12907 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12908 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12909 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12910 | MockRead("\r\n"), |
| 12911 | MockRead("hello world"), |
| 12912 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12913 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12914 | }; |
| 12915 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12916 | StaticSocketDataProvider first_transaction(data_reads, |
| 12917 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12918 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12919 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12920 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12921 | ssl.ssl_info.cert = |
| 12922 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12923 | ASSERT_TRUE(ssl.ssl_info.cert); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12924 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12925 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12926 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12927 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12928 | hanging_alternate_protocol_socket.set_connect_data( |
| 12929 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12930 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12931 | &hanging_alternate_protocol_socket); |
| 12932 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12933 | // 2nd request is just a copy of the first one, over HTTP/1.1 again. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12934 | StaticSocketDataProvider second_transaction(data_reads, |
| 12935 | base::span<MockWrite>()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12936 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12937 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12938 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12939 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12940 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12941 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12942 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12943 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12944 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12945 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12946 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12947 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12948 | |
| 12949 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12950 | ASSERT_TRUE(response); |
| 12951 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12952 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12953 | |
| 12954 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12955 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12956 | EXPECT_EQ("hello world", response_data); |
| 12957 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12958 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12959 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12960 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12961 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12962 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12963 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12964 | |
| 12965 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12966 | ASSERT_TRUE(response); |
| 12967 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12968 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12969 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12970 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12971 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12972 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12973 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12974 | } |
| 12975 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12976 | // Test that proxy is resolved using the origin url, |
| 12977 | // regardless of the alternative server. |
| 12978 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 12979 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 12980 | ProxyConfig proxy_config; |
| 12981 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 12982 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 12983 | auto proxy_config_service = std::make_unique<ProxyConfigServiceFixed>( |
| 12984 | ProxyConfigWithAnnotation(proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12985 | |
| 12986 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12987 | auto proxy_resolver_factory = std::make_unique<CapturingProxyResolverFactory>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12988 | &capturing_proxy_resolver); |
| 12989 | |
| 12990 | TestNetLog net_log; |
| 12991 | |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 12992 | session_deps_.proxy_resolution_service = |
| 12993 | std::make_unique<ProxyResolutionService>( |
| 12994 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 12995 | &net_log); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12996 | |
| 12997 | session_deps_.net_log = &net_log; |
| 12998 | |
| 12999 | // Configure alternative service with a hostname that is not bypassed by the |
| 13000 | // proxy. |
| 13001 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13002 | HttpServerProperties* http_server_properties = |
| 13003 | session->http_server_properties(); |
| 13004 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 13005 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13006 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13007 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13008 | http_server_properties->SetHttp2AlternativeService( |
| 13009 | server, alternative_service, expiration); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13010 | |
| 13011 | // Non-alternative job should hang. |
| 13012 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13013 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13014 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 13015 | session_deps_.socket_factory->AddSocketDataProvider( |
| 13016 | &hanging_alternate_protocol_socket); |
| 13017 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13018 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13019 | |
| 13020 | HttpRequestInfo request; |
| 13021 | request.method = "GET"; |
| 13022 | request.url = GURL("https://www.example.org/"); |
| 13023 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13024 | request.traffic_annotation = |
| 13025 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13026 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13027 | spdy::SpdySerializedFrame req( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13028 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 13029 | |
| 13030 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 13031 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13032 | spdy::SpdySerializedFrame resp( |
| 13033 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 13034 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13035 | MockRead spdy_reads[] = { |
| 13036 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 13037 | }; |
| 13038 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13039 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13040 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 13041 | |
| 13042 | TestCompletionCallback callback; |
| 13043 | |
| 13044 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 13045 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13046 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13047 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 13048 | |
| 13049 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 13050 | ASSERT_TRUE(response); |
| 13051 | ASSERT_TRUE(response->headers); |
| 13052 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 13053 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13054 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13055 | |
| 13056 | std::string response_data; |
| 13057 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 13058 | EXPECT_EQ("hello!", response_data); |
| 13059 | |
| 13060 | // Origin host bypasses proxy, no resolution should have happened. |
| 13061 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 13062 | } |
| 13063 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13064 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13065 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 13066 | proxy_config.set_auto_detect(true); |
| 13067 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 13068 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13069 | CapturingProxyResolver capturing_proxy_resolver; |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13070 | session_deps_.proxy_resolution_service = |
| 13071 | std::make_unique<ProxyResolutionService>( |
| 13072 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 13073 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 13074 | std::make_unique<CapturingProxyResolverFactory>( |
| 13075 | &capturing_proxy_resolver), |
| 13076 | nullptr); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13077 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13078 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13079 | |
| 13080 | HttpRequestInfo request; |
| 13081 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13082 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13083 | request.traffic_annotation = |
| 13084 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13085 | |
| 13086 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13087 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13088 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13089 | MockRead("\r\n"), |
| 13090 | MockRead("hello world"), |
| 13091 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 13092 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13093 | }; |
| 13094 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13095 | StaticSocketDataProvider first_transaction(data_reads, |
| 13096 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13097 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13098 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13099 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13100 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13101 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13102 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13103 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13104 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13105 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13106 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13107 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13108 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13109 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13110 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13111 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13112 | }; |
| 13113 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 13114 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 13115 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13116 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 13117 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13118 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13119 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 13120 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13121 | }; |
| 13122 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13123 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13124 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13125 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13126 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13127 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13128 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 13129 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13130 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13131 | &hanging_non_alternate_protocol_socket); |
| 13132 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13133 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13134 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13135 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13136 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13137 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13138 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13139 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13140 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13141 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 13142 | |
| 13143 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13144 | ASSERT_TRUE(response); |
| 13145 | ASSERT_TRUE(response->headers); |
| 13146 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 13147 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13148 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13149 | |
| 13150 | std::string response_data; |
| 13151 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 13152 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13153 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13154 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13155 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13156 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13157 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13158 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13159 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13160 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13161 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13162 | ASSERT_TRUE(response); |
| 13163 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13164 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13165 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13166 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13167 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13168 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13169 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13170 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 13171 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13172 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13173 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13174 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13175 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13176 | LoadTimingInfo load_timing_info; |
| 13177 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 13178 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13179 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13180 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13181 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13182 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 13183 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13184 | HttpRequestInfo request; |
| 13185 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13186 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13187 | request.traffic_annotation = |
| 13188 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13189 | |
| 13190 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13191 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13192 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13193 | MockRead("\r\n"), |
| 13194 | MockRead("hello world"), |
| 13195 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13196 | }; |
| 13197 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13198 | StaticSocketDataProvider first_transaction(data_reads, |
| 13199 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13200 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13201 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13202 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13203 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13204 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13205 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13206 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13207 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13208 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13209 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13210 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13211 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 13212 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13213 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13214 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13215 | }; |
| 13216 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13217 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13218 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13219 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 13220 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13221 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13222 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13223 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13224 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13225 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13226 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13227 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13228 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13229 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13230 | |
| 13231 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13232 | ASSERT_TRUE(response); |
| 13233 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13234 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13235 | |
| 13236 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13237 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13238 | EXPECT_EQ("hello world", response_data); |
| 13239 | |
| 13240 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13241 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13242 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 13243 | PRIVACY_MODE_DISABLED, |
| 13244 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13245 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 13246 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 13247 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13248 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13249 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13250 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13251 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13252 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13253 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13254 | |
| 13255 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13256 | ASSERT_TRUE(response); |
| 13257 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13258 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13259 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13260 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13261 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13262 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13263 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13264 | } |
| 13265 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13266 | // GenerateAuthToken is a mighty big test. |
| 13267 | // It tests all permutation of GenerateAuthToken behavior: |
| 13268 | // - Synchronous and Asynchronous completion. |
| 13269 | // - OK or error on completion. |
| 13270 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 13271 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 13272 | // - Non-authenticating and authenticating backend. |
| 13273 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 13274 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13275 | // problems generating an auth token for an authenticating proxy, we don't |
| 13276 | // need to test all permutations of the backend server). |
| 13277 | // |
| 13278 | // The test proceeds by going over each of the configuration cases, and |
| 13279 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 13280 | // specifies both the configuration for the test as well as the expectations |
| 13281 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13282 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13283 | static const char kServer[] = "http://www.example.com"; |
| 13284 | static const char kSecureServer[] = "https://www.example.com"; |
| 13285 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13286 | |
| 13287 | enum AuthTiming { |
| 13288 | AUTH_NONE, |
| 13289 | AUTH_SYNC, |
| 13290 | AUTH_ASYNC, |
| 13291 | }; |
| 13292 | |
| 13293 | const MockWrite kGet( |
| 13294 | "GET / HTTP/1.1\r\n" |
| 13295 | "Host: www.example.com\r\n" |
| 13296 | "Connection: keep-alive\r\n\r\n"); |
| 13297 | const MockWrite kGetProxy( |
| 13298 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13299 | "Host: www.example.com\r\n" |
| 13300 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 13301 | const MockWrite kGetAuth( |
| 13302 | "GET / HTTP/1.1\r\n" |
| 13303 | "Host: www.example.com\r\n" |
| 13304 | "Connection: keep-alive\r\n" |
| 13305 | "Authorization: auth_token\r\n\r\n"); |
| 13306 | const MockWrite kGetProxyAuth( |
| 13307 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13308 | "Host: www.example.com\r\n" |
| 13309 | "Proxy-Connection: keep-alive\r\n" |
| 13310 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 13311 | const MockWrite kGetAuthThroughProxy( |
| 13312 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13313 | "Host: www.example.com\r\n" |
| 13314 | "Proxy-Connection: keep-alive\r\n" |
| 13315 | "Authorization: auth_token\r\n\r\n"); |
| 13316 | const MockWrite kGetAuthWithProxyAuth( |
| 13317 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13318 | "Host: www.example.com\r\n" |
| 13319 | "Proxy-Connection: keep-alive\r\n" |
| 13320 | "Proxy-Authorization: auth_token\r\n" |
| 13321 | "Authorization: auth_token\r\n\r\n"); |
| 13322 | const MockWrite kConnect( |
| 13323 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13324 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13325 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 13326 | const MockWrite kConnectProxyAuth( |
| 13327 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13328 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13329 | "Proxy-Connection: keep-alive\r\n" |
| 13330 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 13331 | |
| 13332 | const MockRead kSuccess( |
| 13333 | "HTTP/1.1 200 OK\r\n" |
| 13334 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13335 | "Content-Length: 3\r\n\r\n" |
| 13336 | "Yes"); |
| 13337 | const MockRead kFailure( |
| 13338 | "Should not be called."); |
| 13339 | const MockRead kServerChallenge( |
| 13340 | "HTTP/1.1 401 Unauthorized\r\n" |
| 13341 | "WWW-Authenticate: Mock realm=server\r\n" |
| 13342 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13343 | "Content-Length: 14\r\n\r\n" |
| 13344 | "Unauthorized\r\n"); |
| 13345 | const MockRead kProxyChallenge( |
| 13346 | "HTTP/1.1 407 Unauthorized\r\n" |
| 13347 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 13348 | "Proxy-Connection: close\r\n" |
| 13349 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13350 | "Content-Length: 14\r\n\r\n" |
| 13351 | "Unauthorized\r\n"); |
| 13352 | const MockRead kProxyConnected( |
| 13353 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 13354 | |
| 13355 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 13356 | // no constructors, but the C++ compiler on Windows warns about |
| 13357 | // unspecified data in compound literals. So, moved to using constructors, |
| 13358 | // and TestRound's created with the default constructor should not be used. |
| 13359 | struct TestRound { |
| 13360 | TestRound() |
| 13361 | : expected_rv(ERR_UNEXPECTED), |
| 13362 | extra_write(NULL), |
| 13363 | extra_read(NULL) { |
| 13364 | } |
| 13365 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 13366 | int expected_rv_arg) |
| 13367 | : write(write_arg), |
| 13368 | read(read_arg), |
| 13369 | expected_rv(expected_rv_arg), |
| 13370 | extra_write(NULL), |
| 13371 | extra_read(NULL) { |
| 13372 | } |
| 13373 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 13374 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 13375 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13376 | : write(write_arg), |
| 13377 | read(read_arg), |
| 13378 | expected_rv(expected_rv_arg), |
| 13379 | extra_write(extra_write_arg), |
| 13380 | extra_read(extra_read_arg) { |
| 13381 | } |
| 13382 | MockWrite write; |
| 13383 | MockRead read; |
| 13384 | int expected_rv; |
| 13385 | const MockWrite* extra_write; |
| 13386 | const MockRead* extra_read; |
| 13387 | }; |
| 13388 | |
| 13389 | static const int kNoSSL = 500; |
| 13390 | |
| 13391 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13392 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13393 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13394 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13395 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13396 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13397 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13398 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13399 | int num_auth_rounds; |
| 13400 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13401 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13402 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13403 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13404 | {__LINE__, |
| 13405 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13406 | AUTH_NONE, |
| 13407 | OK, |
| 13408 | kServer, |
| 13409 | AUTH_NONE, |
| 13410 | OK, |
| 13411 | 1, |
| 13412 | kNoSSL, |
| 13413 | {TestRound(kGet, kSuccess, OK)}}, |
| 13414 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13415 | {__LINE__, |
| 13416 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13417 | AUTH_NONE, |
| 13418 | OK, |
| 13419 | kServer, |
| 13420 | AUTH_SYNC, |
| 13421 | OK, |
| 13422 | 2, |
| 13423 | kNoSSL, |
| 13424 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13425 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13426 | {__LINE__, |
| 13427 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13428 | AUTH_NONE, |
| 13429 | OK, |
| 13430 | kServer, |
| 13431 | AUTH_SYNC, |
| 13432 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13433 | 3, |
| 13434 | kNoSSL, |
| 13435 | {TestRound(kGet, kServerChallenge, OK), |
| 13436 | TestRound(kGet, kServerChallenge, OK), |
| 13437 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13438 | {__LINE__, |
| 13439 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13440 | AUTH_NONE, |
| 13441 | OK, |
| 13442 | kServer, |
| 13443 | AUTH_SYNC, |
| 13444 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 13445 | 2, |
| 13446 | kNoSSL, |
| 13447 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13448 | {__LINE__, |
| 13449 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13450 | AUTH_NONE, |
| 13451 | OK, |
| 13452 | kServer, |
| 13453 | AUTH_SYNC, |
| 13454 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 13455 | 2, |
| 13456 | kNoSSL, |
| 13457 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13458 | {__LINE__, |
| 13459 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13460 | AUTH_SYNC, |
| 13461 | ERR_FAILED, |
| 13462 | kServer, |
| 13463 | AUTH_NONE, |
| 13464 | OK, |
| 13465 | 2, |
| 13466 | kNoSSL, |
| 13467 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13468 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13469 | {__LINE__, |
| 13470 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13471 | AUTH_ASYNC, |
| 13472 | ERR_FAILED, |
| 13473 | kServer, |
| 13474 | AUTH_NONE, |
| 13475 | OK, |
| 13476 | 2, |
| 13477 | kNoSSL, |
| 13478 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13479 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13480 | {__LINE__, |
| 13481 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13482 | AUTH_NONE, |
| 13483 | OK, |
| 13484 | kServer, |
| 13485 | AUTH_SYNC, |
| 13486 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13487 | 2, |
| 13488 | kNoSSL, |
| 13489 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13490 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13491 | {__LINE__, |
| 13492 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13493 | AUTH_NONE, |
| 13494 | OK, |
| 13495 | kServer, |
| 13496 | AUTH_ASYNC, |
| 13497 | ERR_FAILED, |
| 13498 | 2, |
| 13499 | kNoSSL, |
| 13500 | {TestRound(kGet, kServerChallenge, OK), |
| 13501 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13502 | {__LINE__, |
| 13503 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13504 | AUTH_NONE, |
| 13505 | OK, |
| 13506 | kServer, |
| 13507 | AUTH_ASYNC, |
| 13508 | OK, |
| 13509 | 2, |
| 13510 | kNoSSL, |
| 13511 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13512 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13513 | {__LINE__, |
| 13514 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13515 | AUTH_NONE, |
| 13516 | OK, |
| 13517 | kServer, |
| 13518 | AUTH_ASYNC, |
| 13519 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13520 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13521 | kNoSSL, |
| 13522 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13523 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 13524 | TestRound(kGet, kServerChallenge, OK), |
| 13525 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13526 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13527 | {__LINE__, |
| 13528 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13529 | AUTH_NONE, |
| 13530 | OK, |
| 13531 | kServer, |
| 13532 | AUTH_NONE, |
| 13533 | OK, |
| 13534 | 1, |
| 13535 | kNoSSL, |
| 13536 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 13537 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13538 | {__LINE__, |
| 13539 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13540 | AUTH_NONE, |
| 13541 | OK, |
| 13542 | kServer, |
| 13543 | AUTH_SYNC, |
| 13544 | OK, |
| 13545 | 2, |
| 13546 | kNoSSL, |
| 13547 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13548 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13549 | {__LINE__, |
| 13550 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13551 | AUTH_NONE, |
| 13552 | OK, |
| 13553 | kServer, |
| 13554 | AUTH_SYNC, |
| 13555 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13556 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13557 | kNoSSL, |
| 13558 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13559 | TestRound(kGetProxy, kServerChallenge, OK), |
| 13560 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13561 | {__LINE__, |
| 13562 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13563 | AUTH_NONE, |
| 13564 | OK, |
| 13565 | kServer, |
| 13566 | AUTH_ASYNC, |
| 13567 | OK, |
| 13568 | 2, |
| 13569 | kNoSSL, |
| 13570 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13571 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13572 | {__LINE__, |
| 13573 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13574 | AUTH_NONE, |
| 13575 | OK, |
| 13576 | kServer, |
| 13577 | AUTH_ASYNC, |
| 13578 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13579 | 2, |
| 13580 | kNoSSL, |
| 13581 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13582 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13583 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13584 | {__LINE__, |
| 13585 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13586 | AUTH_SYNC, |
| 13587 | OK, |
| 13588 | kServer, |
| 13589 | AUTH_NONE, |
| 13590 | OK, |
| 13591 | 2, |
| 13592 | kNoSSL, |
| 13593 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13594 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13595 | {__LINE__, |
| 13596 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13597 | AUTH_SYNC, |
| 13598 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13599 | kServer, |
| 13600 | AUTH_NONE, |
| 13601 | OK, |
| 13602 | 2, |
| 13603 | kNoSSL, |
| 13604 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13605 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13606 | {__LINE__, |
| 13607 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13608 | AUTH_ASYNC, |
| 13609 | OK, |
| 13610 | kServer, |
| 13611 | AUTH_NONE, |
| 13612 | OK, |
| 13613 | 2, |
| 13614 | kNoSSL, |
| 13615 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13616 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13617 | {__LINE__, |
| 13618 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13619 | AUTH_ASYNC, |
| 13620 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13621 | kServer, |
| 13622 | AUTH_NONE, |
| 13623 | OK, |
| 13624 | 2, |
| 13625 | kNoSSL, |
| 13626 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13627 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13628 | {__LINE__, |
| 13629 | kProxy, |
| 13630 | AUTH_ASYNC, |
| 13631 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13632 | kServer, |
| 13633 | AUTH_NONE, |
| 13634 | OK, |
| 13635 | 3, |
| 13636 | kNoSSL, |
| 13637 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13638 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13639 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13640 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13641 | {__LINE__, |
| 13642 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13643 | AUTH_SYNC, |
| 13644 | OK, |
| 13645 | kServer, |
| 13646 | AUTH_SYNC, |
| 13647 | OK, |
| 13648 | 3, |
| 13649 | kNoSSL, |
| 13650 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13651 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13652 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13653 | {__LINE__, |
| 13654 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13655 | AUTH_SYNC, |
| 13656 | OK, |
| 13657 | kServer, |
| 13658 | AUTH_SYNC, |
| 13659 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13660 | 3, |
| 13661 | kNoSSL, |
| 13662 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13663 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13664 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13665 | {__LINE__, |
| 13666 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13667 | AUTH_ASYNC, |
| 13668 | OK, |
| 13669 | kServer, |
| 13670 | AUTH_SYNC, |
| 13671 | OK, |
| 13672 | 3, |
| 13673 | kNoSSL, |
| 13674 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13675 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13676 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13677 | {__LINE__, |
| 13678 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13679 | AUTH_ASYNC, |
| 13680 | OK, |
| 13681 | kServer, |
| 13682 | AUTH_SYNC, |
| 13683 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13684 | 3, |
| 13685 | kNoSSL, |
| 13686 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13687 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13688 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13689 | {__LINE__, |
| 13690 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13691 | AUTH_SYNC, |
| 13692 | OK, |
| 13693 | kServer, |
| 13694 | AUTH_ASYNC, |
| 13695 | OK, |
| 13696 | 3, |
| 13697 | kNoSSL, |
| 13698 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13699 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13700 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13701 | {__LINE__, |
| 13702 | kProxy, |
| 13703 | AUTH_SYNC, |
| 13704 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13705 | kServer, |
| 13706 | AUTH_ASYNC, |
| 13707 | OK, |
| 13708 | 4, |
| 13709 | kNoSSL, |
| 13710 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13711 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13712 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13713 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 13714 | {__LINE__, |
| 13715 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13716 | AUTH_SYNC, |
| 13717 | OK, |
| 13718 | kServer, |
| 13719 | AUTH_ASYNC, |
| 13720 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13721 | 3, |
| 13722 | kNoSSL, |
| 13723 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13724 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13725 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13726 | {__LINE__, |
| 13727 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13728 | AUTH_ASYNC, |
| 13729 | OK, |
| 13730 | kServer, |
| 13731 | AUTH_ASYNC, |
| 13732 | OK, |
| 13733 | 3, |
| 13734 | kNoSSL, |
| 13735 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13736 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13737 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13738 | {__LINE__, |
| 13739 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13740 | AUTH_ASYNC, |
| 13741 | OK, |
| 13742 | kServer, |
| 13743 | AUTH_ASYNC, |
| 13744 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13745 | 3, |
| 13746 | kNoSSL, |
| 13747 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13748 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13749 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13750 | {__LINE__, |
| 13751 | kProxy, |
| 13752 | AUTH_ASYNC, |
| 13753 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13754 | kServer, |
| 13755 | AUTH_ASYNC, |
| 13756 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13757 | 4, |
| 13758 | kNoSSL, |
| 13759 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13760 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13761 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13762 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13763 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13764 | {__LINE__, |
| 13765 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13766 | AUTH_NONE, |
| 13767 | OK, |
| 13768 | kSecureServer, |
| 13769 | AUTH_NONE, |
| 13770 | OK, |
| 13771 | 1, |
| 13772 | 0, |
| 13773 | {TestRound(kGet, kSuccess, OK)}}, |
| 13774 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13775 | {__LINE__, |
| 13776 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13777 | AUTH_NONE, |
| 13778 | OK, |
| 13779 | kSecureServer, |
| 13780 | AUTH_SYNC, |
| 13781 | OK, |
| 13782 | 2, |
| 13783 | 0, |
| 13784 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13785 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13786 | {__LINE__, |
| 13787 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13788 | AUTH_NONE, |
| 13789 | OK, |
| 13790 | kSecureServer, |
| 13791 | AUTH_SYNC, |
| 13792 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13793 | 2, |
| 13794 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13795 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13796 | {__LINE__, |
| 13797 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13798 | AUTH_NONE, |
| 13799 | OK, |
| 13800 | kSecureServer, |
| 13801 | AUTH_ASYNC, |
| 13802 | OK, |
| 13803 | 2, |
| 13804 | 0, |
| 13805 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13806 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13807 | {__LINE__, |
| 13808 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13809 | AUTH_NONE, |
| 13810 | OK, |
| 13811 | kSecureServer, |
| 13812 | AUTH_ASYNC, |
| 13813 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13814 | 2, |
| 13815 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13816 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13817 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13818 | {__LINE__, |
| 13819 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13820 | AUTH_NONE, |
| 13821 | OK, |
| 13822 | kSecureServer, |
| 13823 | AUTH_NONE, |
| 13824 | OK, |
| 13825 | 1, |
| 13826 | 0, |
| 13827 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 13828 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13829 | {__LINE__, |
| 13830 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13831 | AUTH_NONE, |
| 13832 | OK, |
| 13833 | kSecureServer, |
| 13834 | AUTH_SYNC, |
| 13835 | OK, |
| 13836 | 2, |
| 13837 | 0, |
| 13838 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13839 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13840 | {__LINE__, |
| 13841 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13842 | AUTH_NONE, |
| 13843 | OK, |
| 13844 | kSecureServer, |
| 13845 | AUTH_SYNC, |
| 13846 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13847 | 2, |
| 13848 | 0, |
| 13849 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13850 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13851 | {__LINE__, |
| 13852 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13853 | AUTH_NONE, |
| 13854 | OK, |
| 13855 | kSecureServer, |
| 13856 | AUTH_ASYNC, |
| 13857 | OK, |
| 13858 | 2, |
| 13859 | 0, |
| 13860 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13861 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13862 | {__LINE__, |
| 13863 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13864 | AUTH_NONE, |
| 13865 | OK, |
| 13866 | kSecureServer, |
| 13867 | AUTH_ASYNC, |
| 13868 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13869 | 2, |
| 13870 | 0, |
| 13871 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13872 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13873 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13874 | {__LINE__, |
| 13875 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13876 | AUTH_SYNC, |
| 13877 | OK, |
| 13878 | kSecureServer, |
| 13879 | AUTH_NONE, |
| 13880 | OK, |
| 13881 | 2, |
| 13882 | 1, |
| 13883 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13884 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13885 | {__LINE__, |
| 13886 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13887 | AUTH_SYNC, |
| 13888 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13889 | kSecureServer, |
| 13890 | AUTH_NONE, |
| 13891 | OK, |
| 13892 | 2, |
| 13893 | kNoSSL, |
| 13894 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13895 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13896 | {__LINE__, |
| 13897 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13898 | AUTH_SYNC, |
| 13899 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 13900 | kSecureServer, |
| 13901 | AUTH_NONE, |
| 13902 | OK, |
| 13903 | 2, |
| 13904 | kNoSSL, |
| 13905 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13906 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13907 | {__LINE__, |
| 13908 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13909 | AUTH_SYNC, |
| 13910 | ERR_UNEXPECTED, |
| 13911 | kSecureServer, |
| 13912 | AUTH_NONE, |
| 13913 | OK, |
| 13914 | 2, |
| 13915 | kNoSSL, |
| 13916 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13917 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13918 | {__LINE__, |
| 13919 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13920 | AUTH_ASYNC, |
| 13921 | OK, |
| 13922 | kSecureServer, |
| 13923 | AUTH_NONE, |
| 13924 | OK, |
| 13925 | 2, |
| 13926 | 1, |
| 13927 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13928 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13929 | {__LINE__, |
| 13930 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13931 | AUTH_ASYNC, |
| 13932 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13933 | kSecureServer, |
| 13934 | AUTH_NONE, |
| 13935 | OK, |
| 13936 | 2, |
| 13937 | kNoSSL, |
| 13938 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13939 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13940 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13941 | {__LINE__, |
| 13942 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13943 | AUTH_SYNC, |
| 13944 | OK, |
| 13945 | kSecureServer, |
| 13946 | AUTH_SYNC, |
| 13947 | OK, |
| 13948 | 3, |
| 13949 | 1, |
| 13950 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13951 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13952 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13953 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13954 | {__LINE__, |
| 13955 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13956 | AUTH_SYNC, |
| 13957 | OK, |
| 13958 | kSecureServer, |
| 13959 | AUTH_SYNC, |
| 13960 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13961 | 3, |
| 13962 | 1, |
| 13963 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13964 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13965 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13966 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13967 | {__LINE__, |
| 13968 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13969 | AUTH_ASYNC, |
| 13970 | OK, |
| 13971 | kSecureServer, |
| 13972 | AUTH_SYNC, |
| 13973 | OK, |
| 13974 | 3, |
| 13975 | 1, |
| 13976 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13977 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13978 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13979 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13980 | {__LINE__, |
| 13981 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13982 | AUTH_ASYNC, |
| 13983 | OK, |
| 13984 | kSecureServer, |
| 13985 | AUTH_SYNC, |
| 13986 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13987 | 3, |
| 13988 | 1, |
| 13989 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13990 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13991 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13992 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13993 | {__LINE__, |
| 13994 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13995 | AUTH_SYNC, |
| 13996 | OK, |
| 13997 | kSecureServer, |
| 13998 | AUTH_ASYNC, |
| 13999 | OK, |
| 14000 | 3, |
| 14001 | 1, |
| 14002 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14003 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14004 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14005 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14006 | {__LINE__, |
| 14007 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14008 | AUTH_SYNC, |
| 14009 | OK, |
| 14010 | kSecureServer, |
| 14011 | AUTH_ASYNC, |
| 14012 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14013 | 3, |
| 14014 | 1, |
| 14015 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14016 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14017 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14018 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14019 | {__LINE__, |
| 14020 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14021 | AUTH_ASYNC, |
| 14022 | OK, |
| 14023 | kSecureServer, |
| 14024 | AUTH_ASYNC, |
| 14025 | OK, |
| 14026 | 3, |
| 14027 | 1, |
| 14028 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14029 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14030 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14031 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14032 | {__LINE__, |
| 14033 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14034 | AUTH_ASYNC, |
| 14035 | OK, |
| 14036 | kSecureServer, |
| 14037 | AUTH_ASYNC, |
| 14038 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14039 | 3, |
| 14040 | 1, |
| 14041 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14042 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14043 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14044 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14045 | {__LINE__, |
| 14046 | kProxy, |
| 14047 | AUTH_ASYNC, |
| 14048 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14049 | kSecureServer, |
| 14050 | AUTH_ASYNC, |
| 14051 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14052 | 4, |
| 14053 | 2, |
| 14054 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14055 | TestRound(kConnect, kProxyChallenge, OK), |
| 14056 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14057 | &kServerChallenge), |
| 14058 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14059 | }; |
| 14060 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14061 | for (const auto& test_config : test_configs) { |
| 14062 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 14063 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14064 | HttpAuthHandlerMock::Factory* auth_factory( |
| 14065 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14066 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 14067 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 14068 | |
| 14069 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14070 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14071 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14072 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 14073 | std::string auth_challenge = "Mock realm=proxy"; |
| 14074 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14075 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14076 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14077 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14078 | empty_ssl_info, origin, |
| 14079 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14080 | auth_handler->SetGenerateExpectation( |
| 14081 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14082 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14083 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 14084 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14085 | } |
| 14086 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 14087 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14088 | std::string auth_challenge = "Mock realm=server"; |
| 14089 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14090 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14091 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14092 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14093 | empty_ssl_info, origin, |
| 14094 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14095 | auth_handler->SetGenerateExpectation( |
| 14096 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14097 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14098 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14099 | |
| 14100 | // The second handler always succeeds. It should only be used where there |
| 14101 | // are multiple auth sessions for server auth in the same network |
| 14102 | // transaction using the same auth scheme. |
| 14103 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14104 | std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14105 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 14106 | empty_ssl_info, origin, |
| 14107 | NetLogWithSource()); |
| 14108 | second_handler->SetGenerateExpectation(true, OK); |
| 14109 | auth_factory->AddMockHandler(second_handler.release(), |
| 14110 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14111 | } |
| 14112 | if (test_config.proxy_url) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14113 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14114 | ProxyResolutionService::CreateFixed(test_config.proxy_url, |
| 14115 | TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14116 | } else { |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 14117 | session_deps_.proxy_resolution_service = |
| 14118 | ProxyResolutionService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14119 | } |
| 14120 | |
| 14121 | HttpRequestInfo request; |
| 14122 | request.method = "GET"; |
| 14123 | request.url = GURL(test_config.server_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14124 | request.traffic_annotation = |
| 14125 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14126 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14127 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14128 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14129 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 14130 | |
| 14131 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 14132 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14133 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 14134 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14135 | const TestRound& read_write_round = test_config.rounds[round]; |
| 14136 | |
| 14137 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14138 | mock_reads.back().push_back(read_write_round.read); |
| 14139 | mock_writes.back().push_back(read_write_round.write); |
| 14140 | |
| 14141 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 14142 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 14143 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14144 | mock_reads.push_back(std::vector<MockRead>()); |
| 14145 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14146 | } |
| 14147 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14148 | if (read_write_round.extra_read) { |
| 14149 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14150 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14151 | if (read_write_round.extra_write) { |
| 14152 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 14153 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14154 | |
| 14155 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14156 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14157 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14158 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14159 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14160 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14161 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14162 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14163 | data_providers.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14164 | mock_reads[i], mock_writes[i])); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14165 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 14166 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14167 | } |
| 14168 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 14169 | // Transaction must be created after DataProviders, so it's destroyed before |
| 14170 | // they are as well. |
| 14171 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 14172 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14173 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 14174 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14175 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14176 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14177 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14178 | int rv; |
| 14179 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14180 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14181 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14182 | rv = trans.RestartWithAuth( |
| 14183 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14184 | } |
| 14185 | if (rv == ERR_IO_PENDING) |
| 14186 | rv = callback.WaitForResult(); |
| 14187 | |
| 14188 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14189 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14190 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 14191 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14192 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 14193 | continue; |
| 14194 | } |
| 14195 | if (round + 1 < test_config.num_auth_rounds) { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14196 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14197 | } else { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14198 | EXPECT_FALSE(response->auth_challenge); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14199 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14200 | } |
| 14201 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 14202 | } |
| 14203 | } |
| 14204 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14205 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14206 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14207 | HttpAuthHandlerMock::Factory* auth_factory( |
| 14208 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14209 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 14210 | session_deps_.proxy_resolution_service = |
| 14211 | ProxyResolutionService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14212 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14213 | |
| 14214 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 14215 | auth_handler->set_connection_based(true); |
| 14216 | std::string auth_challenge = "Mock realm=server"; |
| 14217 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14218 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14219 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 14220 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14221 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14222 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14223 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14224 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14225 | int rv = OK; |
| 14226 | const HttpResponseInfo* response = NULL; |
| 14227 | HttpRequestInfo request; |
| 14228 | request.method = "GET"; |
| 14229 | request.url = origin; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14230 | request.traffic_annotation = |
| 14231 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14232 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14233 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14234 | |
| 14235 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 14236 | // to validate that the TCP socket is not released to the pool between |
| 14237 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14238 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14239 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14240 | 50, // Max sockets for pool |
| 14241 | 1, // Max sockets per group |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 14242 | session_deps_.host_resolver.get(), session_deps_.socket_factory.get(), |
| 14243 | NULL, session_deps_.net_log); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14244 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 14245 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 14246 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14247 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14248 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14249 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14250 | |
| 14251 | const MockWrite kGet( |
| 14252 | "GET / HTTP/1.1\r\n" |
| 14253 | "Host: www.example.com\r\n" |
| 14254 | "Connection: keep-alive\r\n\r\n"); |
| 14255 | const MockWrite kGetAuth( |
| 14256 | "GET / HTTP/1.1\r\n" |
| 14257 | "Host: www.example.com\r\n" |
| 14258 | "Connection: keep-alive\r\n" |
| 14259 | "Authorization: auth_token\r\n\r\n"); |
| 14260 | |
| 14261 | const MockRead kServerChallenge( |
| 14262 | "HTTP/1.1 401 Unauthorized\r\n" |
| 14263 | "WWW-Authenticate: Mock realm=server\r\n" |
| 14264 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14265 | "Content-Length: 14\r\n\r\n" |
| 14266 | "Unauthorized\r\n"); |
| 14267 | const MockRead kSuccess( |
| 14268 | "HTTP/1.1 200 OK\r\n" |
| 14269 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14270 | "Content-Length: 3\r\n\r\n" |
| 14271 | "Yes"); |
| 14272 | |
| 14273 | MockWrite writes[] = { |
| 14274 | // First round |
| 14275 | kGet, |
| 14276 | // Second round |
| 14277 | kGetAuth, |
| 14278 | // Third round |
| 14279 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14280 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14281 | kGetAuth, |
| 14282 | // Competing request |
| 14283 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14284 | }; |
| 14285 | MockRead reads[] = { |
| 14286 | // First round |
| 14287 | kServerChallenge, |
| 14288 | // Second round |
| 14289 | kServerChallenge, |
| 14290 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14291 | kServerChallenge, |
| 14292 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14293 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14294 | // Competing response |
| 14295 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14296 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14297 | StaticSocketDataProvider data_provider(reads, writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14298 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14299 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 14300 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14301 | |
| 14302 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14303 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14304 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14305 | if (rv == ERR_IO_PENDING) |
| 14306 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14307 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14308 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14309 | ASSERT_TRUE(response); |
| 14310 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14311 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14312 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14313 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14314 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14315 | // In between rounds, another request comes in for the same domain. |
| 14316 | // It should not be able to grab the TCP socket that trans has already |
| 14317 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14318 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14319 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14320 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 14321 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14322 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14323 | // callback_compete.WaitForResult at this point would stall forever, |
| 14324 | // since the HttpNetworkTransaction does not release the request back to |
| 14325 | // the pool until after authentication completes. |
| 14326 | |
| 14327 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14328 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14329 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14330 | if (rv == ERR_IO_PENDING) |
| 14331 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14332 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14333 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14334 | ASSERT_TRUE(response); |
| 14335 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14336 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14337 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14338 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14339 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14340 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14341 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14342 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14343 | if (rv == ERR_IO_PENDING) |
| 14344 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14345 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14346 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14347 | ASSERT_TRUE(response); |
| 14348 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14349 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14350 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14351 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14352 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14353 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14354 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14355 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14356 | if (rv == ERR_IO_PENDING) |
| 14357 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14358 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14359 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14360 | ASSERT_TRUE(response); |
| 14361 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14362 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14363 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14364 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 14365 | // auth handler should transition to a DONE state in concert with the remote |
| 14366 | // server. But that's not something we can test here with a mock handler. |
| 14367 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 14368 | auth_handler->state()); |
| 14369 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14370 | // Read the body since the fourth round was successful. This will also |
| 14371 | // release the socket back to the pool. |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 14372 | scoped_refptr<IOBufferWithSize> io_buf = |
| 14373 | base::MakeRefCounted<IOBufferWithSize>(50); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14374 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14375 | if (rv == ERR_IO_PENDING) |
| 14376 | rv = callback.WaitForResult(); |
| 14377 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14378 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14379 | EXPECT_EQ(0, rv); |
| 14380 | // There are still 0 idle sockets, since the trans_compete transaction |
| 14381 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14382 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14383 | |
| 14384 | // The competing request can now finish. Wait for the headers and then |
| 14385 | // read the body. |
| 14386 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14387 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14388 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14389 | if (rv == ERR_IO_PENDING) |
| 14390 | rv = callback.WaitForResult(); |
| 14391 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14392 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14393 | EXPECT_EQ(0, rv); |
| 14394 | |
| 14395 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14396 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14397 | } |
| 14398 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14399 | // This tests the case that a request is issued via http instead of spdy after |
| 14400 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14401 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14402 | HttpRequestInfo request; |
| 14403 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14404 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14405 | request.traffic_annotation = |
| 14406 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14407 | |
| 14408 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14409 | MockWrite( |
| 14410 | "GET / HTTP/1.1\r\n" |
| 14411 | "Host: www.example.org\r\n" |
| 14412 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14413 | }; |
| 14414 | |
| 14415 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14416 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 14417 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14418 | MockRead("\r\n"), |
| 14419 | MockRead("hello world"), |
| 14420 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14421 | }; |
| 14422 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14423 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14424 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14425 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14426 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14427 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14428 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14429 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14430 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14431 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14432 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14433 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14434 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14435 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14436 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14437 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14438 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14439 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14440 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14441 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14442 | ASSERT_TRUE(response); |
| 14443 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14444 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14445 | |
| 14446 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14447 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14448 | EXPECT_EQ("hello world", response_data); |
| 14449 | |
| 14450 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14451 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14452 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14453 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 14454 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 14455 | // immediate server closing of the socket. |
| 14456 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14457 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14458 | HttpRequestInfo request; |
| 14459 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14460 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14461 | request.traffic_annotation = |
| 14462 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14463 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14464 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14465 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14466 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14467 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14468 | spdy::SpdySerializedFrame req( |
| 14469 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14470 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14471 | |
| 14472 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14473 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14474 | }; |
| 14475 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14476 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14477 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14478 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14479 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14480 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14481 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14482 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14483 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14484 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14485 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14486 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14487 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 14488 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14489 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 14490 | // it gets it. This is needed since the auth handler may get destroyed |
| 14491 | // before we get a chance to query it. |
| 14492 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 14493 | public: |
| 14494 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 14495 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 14496 | ~UrlRecordingHttpAuthHandlerMock() override = default; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14497 | |
| 14498 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14499 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 14500 | const HttpRequestInfo* request, |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame] | 14501 | CompletionOnceCallback callback, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14502 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14503 | *url_ = request->url; |
| 14504 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame] | 14505 | credentials, request, std::move(callback), auth_token); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14506 | } |
| 14507 | |
| 14508 | private: |
| 14509 | GURL* url_; |
| 14510 | }; |
| 14511 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14512 | // Test that if we cancel the transaction as the connection is completing, that |
| 14513 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14514 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14515 | // Setup everything about the connection to complete synchronously, so that |
| 14516 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 14517 | // for is the callback from the HttpStreamRequest. |
| 14518 | // Then cancel the transaction. |
| 14519 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 14520 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14521 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14522 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 14523 | MockRead(SYNCHRONOUS, "hello world"), |
| 14524 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14525 | }; |
| 14526 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14527 | HttpRequestInfo request; |
| 14528 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14529 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14530 | request.traffic_annotation = |
| 14531 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14532 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14533 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14534 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14535 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14536 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14537 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14538 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14539 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14540 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14541 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14542 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14543 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14544 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14545 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14546 | trans.reset(); // Cancel the transaction here. |
| 14547 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14548 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 14549 | } |
| 14550 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14551 | // Test that if a transaction is cancelled after receiving the headers, the |
| 14552 | // stream is drained properly and added back to the socket pool. The main |
| 14553 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 14554 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 14555 | // deleted. |
| 14556 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14557 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14558 | MockRead data_reads[] = { |
| 14559 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 14560 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 14561 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 14562 | MockRead(ASYNC, "1"), |
| 14563 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 14564 | // HttpNetworkTransaction has been deleted. |
| 14565 | MockRead(ASYNC, "2"), |
| 14566 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 14567 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14568 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14569 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14570 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14571 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14572 | |
| 14573 | { |
| 14574 | HttpRequestInfo request; |
| 14575 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14576 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14577 | request.traffic_annotation = |
| 14578 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14579 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14580 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14581 | TestCompletionCallback callback; |
| 14582 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14583 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14584 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14585 | callback.WaitForResult(); |
| 14586 | |
| 14587 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14588 | ASSERT_TRUE(response); |
| 14589 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14590 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14591 | |
| 14592 | // The transaction and HttpRequestInfo are deleted. |
| 14593 | } |
| 14594 | |
| 14595 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14596 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14597 | |
| 14598 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14599 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14600 | } |
| 14601 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14602 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14603 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14604 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14605 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14606 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14607 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14608 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14609 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14610 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14611 | HttpRequestInfo request; |
| 14612 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14613 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14614 | request.traffic_annotation = |
| 14615 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14616 | |
| 14617 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14618 | MockWrite( |
| 14619 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 14620 | "Host: www.example.org\r\n" |
| 14621 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14622 | }; |
| 14623 | |
| 14624 | MockRead data_reads1[] = { |
| 14625 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14626 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14627 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14628 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14629 | }; |
| 14630 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14631 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14632 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14633 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14634 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14635 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14636 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14637 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14638 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14639 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 14640 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14641 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14642 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14643 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14644 | |
| 14645 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14646 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14647 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14648 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14649 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14650 | |
| 14651 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14652 | EXPECT_EQ(200, response->headers->response_code()); |
| 14653 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14654 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14655 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14656 | HostPortPair::FromString("myproxy:70")), |
| 14657 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14658 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 14659 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 14660 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14661 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14662 | |
| 14663 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14664 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14665 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14666 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14667 | } |
| 14668 | |
| 14669 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14670 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14671 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14672 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14673 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14674 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14675 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14676 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14677 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14678 | HttpRequestInfo request; |
| 14679 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14680 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14681 | request.traffic_annotation = |
| 14682 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14683 | |
| 14684 | // Since we have proxy, should try to establish tunnel. |
| 14685 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14686 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14687 | "Host: www.example.org:443\r\n" |
| 14688 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14689 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14690 | MockWrite("GET / HTTP/1.1\r\n" |
| 14691 | "Host: www.example.org\r\n" |
| 14692 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14693 | }; |
| 14694 | |
| 14695 | MockRead data_reads1[] = { |
| 14696 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14697 | |
| 14698 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14699 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14700 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14701 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14702 | }; |
| 14703 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14704 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14705 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14706 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14707 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14708 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14709 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14710 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14711 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14712 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14713 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14714 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 14715 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14716 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14717 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14718 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14719 | |
| 14720 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14721 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 14722 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14723 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14724 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14725 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14726 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14727 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14728 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14729 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14730 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14731 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14732 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14733 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14734 | |
| 14735 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14736 | EXPECT_EQ(200, response->headers->response_code()); |
| 14737 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14738 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 14739 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14740 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14741 | HostPortPair::FromString("myproxy:70")), |
| 14742 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14743 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 14744 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 14745 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14746 | |
| 14747 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14748 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14749 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14750 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14751 | } |
| 14752 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14753 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 14754 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14755 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14756 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14757 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14758 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14759 | BoundTestNetLog log; |
| 14760 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14761 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14762 | |
| 14763 | HttpRequestInfo request; |
| 14764 | request.method = "GET"; |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14765 | request.url = GURL("https://[::2]:443/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14766 | request.traffic_annotation = |
| 14767 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14768 | |
| 14769 | // Since we have proxy, should try to establish tunnel. |
| 14770 | MockWrite data_writes1[] = { |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14771 | MockWrite("CONNECT [::2]:443 HTTP/1.1\r\n" |
| 14772 | "Host: [::2]:443\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14773 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 14774 | |
| 14775 | MockWrite("GET / HTTP/1.1\r\n" |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14776 | "Host: [::2]\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14777 | "Connection: keep-alive\r\n\r\n"), |
| 14778 | }; |
| 14779 | |
| 14780 | MockRead data_reads1[] = { |
| 14781 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14782 | |
| 14783 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14784 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14785 | MockRead("Content-Length: 100\r\n\r\n"), |
| 14786 | MockRead(SYNCHRONOUS, OK), |
| 14787 | }; |
| 14788 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14789 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14790 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14791 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14792 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14793 | |
| 14794 | TestCompletionCallback callback1; |
| 14795 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14796 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14797 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14798 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14799 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14800 | |
| 14801 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14802 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14803 | TestNetLogEntry::List entries; |
| 14804 | log.GetEntries(&entries); |
| 14805 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14806 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14807 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14808 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14809 | entries, pos, |
| 14810 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14811 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14812 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14813 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14814 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14815 | |
| 14816 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14817 | EXPECT_EQ(200, response->headers->response_code()); |
| 14818 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14819 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 14820 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14821 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14822 | HostPortPair::FromString("myproxy:70")), |
| 14823 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14824 | |
| 14825 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14826 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14827 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14828 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 14829 | } |
| 14830 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14831 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 14832 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14833 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14834 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 14835 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14836 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14837 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14838 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14839 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14840 | HttpRequestInfo request; |
| 14841 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14842 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14843 | request.traffic_annotation = |
| 14844 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14845 | |
| 14846 | // Since we have proxy, should try to establish tunnel. |
| 14847 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14848 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14849 | "Host: www.example.org:443\r\n" |
| 14850 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14851 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14852 | MockWrite("GET / HTTP/1.1\r\n" |
| 14853 | "Host: www.example.org\r\n" |
| 14854 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14855 | }; |
| 14856 | |
| 14857 | MockRead data_reads1[] = { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14858 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14859 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14860 | }; |
| 14861 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14862 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14863 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14864 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14865 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14866 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14867 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14868 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14869 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14870 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14871 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14872 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14873 | |
| 14874 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14875 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 14876 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14877 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14878 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14879 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14880 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14881 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14882 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14883 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14884 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14885 | } |
| 14886 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14887 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14888 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14889 | spdy::SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14890 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14891 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14892 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14893 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 14894 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14895 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14896 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14897 | }; |
| 14898 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14899 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14900 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14901 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14902 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14903 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14904 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14905 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14906 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14907 | |
| 14908 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14909 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14910 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 14911 | PRIVACY_MODE_DISABLED, |
| 14912 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14913 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 14914 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14915 | |
| 14916 | HttpRequestInfo request; |
| 14917 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14918 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14919 | request.traffic_annotation = |
| 14920 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14921 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14922 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14923 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14924 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14925 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14926 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14927 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14928 | } |
| 14929 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14930 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14931 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 14932 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14933 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14934 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14935 | request_info.url = GURL("https://www.example.com/"); |
| 14936 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14937 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14938 | request_info.traffic_annotation = |
| 14939 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14940 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14941 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14942 | MockWrite data_writes[] = { |
| 14943 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14944 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14945 | StaticSocketDataProvider data(base::span<MockRead>(), data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14946 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14947 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14948 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14949 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14950 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14951 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14952 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14953 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14954 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14955 | rv = callback.WaitForResult(); |
| 14956 | ASSERT_EQ(error, rv); |
| 14957 | } |
| 14958 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14959 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14960 | // Just check a grab bag of cert errors. |
| 14961 | static const int kErrors[] = { |
| 14962 | ERR_CERT_COMMON_NAME_INVALID, |
| 14963 | ERR_CERT_AUTHORITY_INVALID, |
| 14964 | ERR_CERT_DATE_INVALID, |
| 14965 | }; |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 14966 | for (size_t i = 0; i < base::size(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14967 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 14968 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14969 | } |
| 14970 | } |
| 14971 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14972 | // Ensure that a client certificate is removed from the SSL client auth |
| 14973 | // cache when: |
| 14974 | // 1) No proxy is involved. |
| 14975 | // 2) TLS False Start is disabled. |
| 14976 | // 3) The initial TLS handshake requests a client certificate. |
| 14977 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14978 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14979 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14980 | request_info.url = GURL("https://www.example.com/"); |
| 14981 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14982 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14983 | request_info.traffic_annotation = |
| 14984 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14985 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14986 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14987 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14988 | |
| 14989 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 14990 | // CertificateRequest is received for the first time, the handshake will |
| 14991 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14992 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14993 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14994 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14995 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14996 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14997 | |
| 14998 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 14999 | // False Start is not being used, the result of the SSL handshake will be |
| 15000 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 15001 | // matches the result of a server sending a handshake_failure alert, |
| 15002 | // rather than a Finished message, because it requires a client |
| 15003 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15004 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15005 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15006 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15007 | StaticSocketDataProvider data2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15008 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15009 | |
| 15010 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 15011 | // connection to a server fails during an SSL handshake, |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 15012 | // HttpNetworkTransaction will attempt to fallback to TLSv1.2 if the previous |
| 15013 | // connection was attempted with TLSv1.3. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15014 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 15015 | // requiring a client certificate, this fallback handshake should also |
| 15016 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15017 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 15018 | ssl_data3.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15019 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15020 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15021 | StaticSocketDataProvider data3; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15022 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15023 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15024 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 15025 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 15026 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 15027 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15028 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 15029 | // requiring a client certificate, this fallback handshake should also |
| 15030 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15031 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15032 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15033 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15034 | StaticSocketDataProvider data4; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15035 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15036 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15037 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15038 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15039 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15040 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15041 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15042 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15043 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15044 | |
| 15045 | // Complete the SSL handshake, which should abort due to requiring a |
| 15046 | // client certificate. |
| 15047 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15048 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15049 | |
| 15050 | // Indicate that no certificate should be supplied. From the perspective |
| 15051 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15052 | // certificate, so this is the same as supply a |
| 15053 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15054 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15055 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15056 | |
| 15057 | // Ensure the certificate was added to the client auth cache before |
| 15058 | // allowing the connection to continue restarting. |
| 15059 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15060 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15061 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15062 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15063 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15064 | |
| 15065 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15066 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 15067 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15068 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15069 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15070 | |
| 15071 | // Ensure that the client certificate is removed from the cache on a |
| 15072 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15073 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15074 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15075 | } |
| 15076 | |
| 15077 | // Ensure that a client certificate is removed from the SSL client auth |
| 15078 | // cache when: |
| 15079 | // 1) No proxy is involved. |
| 15080 | // 2) TLS False Start is enabled. |
| 15081 | // 3) The initial TLS handshake requests a client certificate. |
| 15082 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15083 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15084 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15085 | request_info.url = GURL("https://www.example.com/"); |
| 15086 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15087 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15088 | request_info.traffic_annotation = |
| 15089 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15090 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15091 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15092 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15093 | |
| 15094 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 15095 | // return successfully after reading up to the peer's Certificate message. |
| 15096 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 15097 | // enqueue application data to be sent in the same packet as the |
| 15098 | // ChangeCipherSpec and Finished messages. |
| 15099 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 15100 | // called, which expects to process the peer's ChangeCipherSpec and |
| 15101 | // Finished messages. If there was an error negotiating with the peer, |
| 15102 | // such as due to the peer requiring a client certificate when none was |
| 15103 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 15104 | // called. |
| 15105 | |
| 15106 | // Like the non-False Start case, when a client certificate is requested by |
| 15107 | // the peer, the handshake is aborted during the Connect() call. |
| 15108 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15109 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15110 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15111 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15112 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15113 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15114 | |
| 15115 | // When a client certificate is supplied, Connect() will not be aborted |
| 15116 | // when the peer requests the certificate. Instead, the handshake will |
| 15117 | // artificially succeed, allowing the caller to write the HTTP request to |
| 15118 | // the socket. The handshake messages are not processed until Read() is |
| 15119 | // called, which then detects that the handshake was aborted, due to the |
| 15120 | // peer sending a handshake_failure because it requires a client |
| 15121 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15122 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15123 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15124 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15125 | MockRead data2_reads[] = { |
| 15126 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15127 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15128 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15129 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15130 | |
| 15131 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15132 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 15133 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15134 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15135 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15136 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15137 | StaticSocketDataProvider data3(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15138 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15139 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15140 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 15141 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15142 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15143 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15144 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15145 | StaticSocketDataProvider data4(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15146 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15147 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15148 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15149 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15150 | ssl_data5.cert_request_info = cert_request.get(); |
| 15151 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15152 | StaticSocketDataProvider data5(data2_reads, base::span<MockWrite>()); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15153 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 15154 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15155 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15156 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15157 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15158 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15159 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15160 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15161 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15162 | |
| 15163 | // Complete the SSL handshake, which should abort due to requiring a |
| 15164 | // client certificate. |
| 15165 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15166 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15167 | |
| 15168 | // Indicate that no certificate should be supplied. From the perspective |
| 15169 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15170 | // certificate, so this is the same as supply a |
| 15171 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15172 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15173 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15174 | |
| 15175 | // Ensure the certificate was added to the client auth cache before |
| 15176 | // allowing the connection to continue restarting. |
| 15177 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15178 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15179 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15180 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15181 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15182 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15183 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15184 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 15185 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15186 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15187 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15188 | |
| 15189 | // Ensure that the client certificate is removed from the cache on a |
| 15190 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15191 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15192 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15193 | } |
| 15194 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15195 | // Ensure that a client certificate is removed from the SSL client auth |
| 15196 | // cache when: |
| 15197 | // 1) An HTTPS proxy is involved. |
| 15198 | // 3) The HTTPS proxy requests a client certificate. |
| 15199 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 15200 | // proxy. |
| 15201 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 15202 | // then for connecting to an HTTP endpoint. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15203 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15204 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 15205 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15206 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15207 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15208 | |
| 15209 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15210 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15211 | |
| 15212 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 15213 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 15214 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 15215 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15216 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15217 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15218 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15219 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15220 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15221 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15222 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15223 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15224 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15225 | StaticSocketDataProvider data2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15226 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15227 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15228 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 15229 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15230 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15231 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15232 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15233 | StaticSocketDataProvider data3; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15234 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15235 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15236 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15237 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15238 | requests[0].url = GURL("https://www.example.com/"); |
| 15239 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15240 | requests[0].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15241 | requests[0].traffic_annotation = |
| 15242 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15243 | |
| 15244 | requests[1].url = GURL("http://www.example.com/"); |
| 15245 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15246 | requests[1].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15247 | requests[1].traffic_annotation = |
| 15248 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15249 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 15250 | for (size_t i = 0; i < base::size(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15251 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15252 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15253 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15254 | |
| 15255 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15256 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15257 | int rv = trans.Start(&requests[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15258 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15259 | |
| 15260 | // Complete the SSL handshake, which should abort due to requiring a |
| 15261 | // client certificate. |
| 15262 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15263 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15264 | |
| 15265 | // Indicate that no certificate should be supplied. From the perspective |
| 15266 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15267 | // certificate, so this is the same as supply a |
| 15268 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15269 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15270 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15271 | |
| 15272 | // Ensure the certificate was added to the client auth cache before |
| 15273 | // allowing the connection to continue restarting. |
| 15274 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15275 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15276 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15277 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15278 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15279 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 15280 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15281 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15282 | HostPortPair("www.example.com", 443), &client_cert, |
| 15283 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15284 | |
| 15285 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 15286 | // then consume ssl_data3, which should also fail. The result code is |
| 15287 | // checked against what ssl_data3 should return. |
| 15288 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15289 | ASSERT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15290 | |
| 15291 | // Now that the new handshake has failed, ensure that the client |
| 15292 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15293 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15294 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15295 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15296 | HostPortPair("www.example.com", 443), &client_cert, |
| 15297 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15298 | } |
| 15299 | } |
| 15300 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15301 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15302 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15303 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15304 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15305 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15306 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15307 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15308 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15309 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15310 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15311 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15312 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15313 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15314 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15315 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15316 | spdy::SpdySerializedFrame host1_resp( |
| 15317 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 15318 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15319 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15320 | spdy::SpdySerializedFrame host2_resp( |
| 15321 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 15322 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15323 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15324 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15325 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15326 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15327 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15328 | }; |
| 15329 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15330 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15331 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15332 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15333 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15334 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 15335 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15336 | HttpRequestInfo request1; |
| 15337 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15338 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15339 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15340 | request1.traffic_annotation = |
| 15341 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15342 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15343 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15344 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15345 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15346 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15347 | |
| 15348 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15349 | ASSERT_TRUE(response); |
| 15350 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15351 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15352 | |
| 15353 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15354 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15355 | EXPECT_EQ("hello!", response_data); |
| 15356 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15357 | // Preload mail.example.com into HostCache. |
| 15358 | HostPortPair host_port("mail.example.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 15359 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15360 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 15361 | std::unique_ptr<HostResolver::Request> request; |
| 15362 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 15363 | &ignored, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15364 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15365 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 15366 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15367 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15368 | |
| 15369 | HttpRequestInfo request2; |
| 15370 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15371 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15372 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15373 | request2.traffic_annotation = |
| 15374 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15375 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15376 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15377 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15378 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15379 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15380 | |
| 15381 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15382 | ASSERT_TRUE(response); |
| 15383 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15384 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15385 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15386 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15387 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15388 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15389 | } |
| 15390 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15391 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15392 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15393 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15394 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15395 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15396 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15397 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15398 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15399 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15400 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15401 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15402 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15403 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15404 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15405 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15406 | spdy::SpdySerializedFrame host1_resp( |
| 15407 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 15408 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15409 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15410 | spdy::SpdySerializedFrame host2_resp( |
| 15411 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 15412 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15413 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15414 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15415 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15416 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15417 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15418 | }; |
| 15419 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15420 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15421 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15422 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15423 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15424 | |
| 15425 | TestCompletionCallback callback; |
| 15426 | HttpRequestInfo request1; |
| 15427 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15428 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15429 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15430 | request1.traffic_annotation = |
| 15431 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15432 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15433 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15434 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15435 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15436 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15437 | |
| 15438 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15439 | ASSERT_TRUE(response); |
| 15440 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15441 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15442 | |
| 15443 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15444 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15445 | EXPECT_EQ("hello!", response_data); |
| 15446 | |
| 15447 | HttpRequestInfo request2; |
| 15448 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15449 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15450 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15451 | request2.traffic_annotation = |
| 15452 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15453 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15454 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15455 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15456 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15457 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15458 | |
| 15459 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15460 | ASSERT_TRUE(response); |
| 15461 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15462 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15463 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15464 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15465 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15466 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15467 | } |
| 15468 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15469 | // Regression test for https://crbug.com/546991. |
| 15470 | // The server might not be able to serve an IP pooled request, and might send a |
| 15471 | // 421 Misdirected Request response status to indicate this. |
| 15472 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 15473 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 15474 | // Two hosts resolve to the same IP address. |
| 15475 | const std::string ip_addr = "1.2.3.4"; |
| 15476 | IPAddress ip; |
| 15477 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 15478 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 15479 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15480 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15481 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 15482 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 15483 | |
| 15484 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15485 | |
| 15486 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15487 | spdy::SpdySerializedFrame req1( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15488 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 15489 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15490 | spdy::SpdySerializedFrame req2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15491 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15492 | spdy::SpdySerializedFrame rst( |
| 15493 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15494 | MockWrite writes1[] = { |
| 15495 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 15496 | CreateMockWrite(rst, 6), |
| 15497 | }; |
| 15498 | |
| 15499 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15500 | spdy::SpdySerializedFrame resp1( |
| 15501 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15502 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 15503 | spdy::SpdyHeaderBlock response_headers; |
| 15504 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 15505 | spdy::SpdySerializedFrame resp2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15506 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 15507 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 15508 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 15509 | |
| 15510 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15511 | SequencedSocketData data1(connect1, reads1, writes1); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15512 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15513 | |
| 15514 | AddSSLSocketData(); |
| 15515 | |
| 15516 | // Retry the second request on a second connection. |
| 15517 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15518 | spdy::SpdySerializedFrame req3( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15519 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 15520 | MockWrite writes2[] = { |
| 15521 | CreateMockWrite(req3, 0), |
| 15522 | }; |
| 15523 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15524 | spdy::SpdySerializedFrame resp3( |
| 15525 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15526 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15527 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 15528 | MockRead(ASYNC, 0, 3)}; |
| 15529 | |
| 15530 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15531 | SequencedSocketData data2(connect2, reads2, writes2); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15532 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 15533 | |
| 15534 | AddSSLSocketData(); |
| 15535 | |
| 15536 | // Preload mail.example.org into HostCache. |
| 15537 | HostPortPair host_port("mail.example.org", 443); |
| 15538 | HostResolver::RequestInfo resolve_info(host_port); |
| 15539 | AddressList ignored; |
| 15540 | std::unique_ptr<HostResolver::Request> request; |
| 15541 | TestCompletionCallback callback; |
| 15542 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 15543 | &ignored, callback.callback(), |
| 15544 | &request, NetLogWithSource()); |
| 15545 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15546 | rv = callback.WaitForResult(); |
| 15547 | EXPECT_THAT(rv, IsOk()); |
| 15548 | |
| 15549 | HttpRequestInfo request1; |
| 15550 | request1.method = "GET"; |
| 15551 | request1.url = GURL("https://www.example.org/"); |
| 15552 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15553 | request1.traffic_annotation = |
| 15554 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15555 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 15556 | |
| 15557 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 15558 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15559 | rv = callback.WaitForResult(); |
| 15560 | EXPECT_THAT(rv, IsOk()); |
| 15561 | |
| 15562 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 15563 | ASSERT_TRUE(response); |
| 15564 | ASSERT_TRUE(response->headers); |
| 15565 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15566 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15567 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15568 | std::string response_data; |
| 15569 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 15570 | EXPECT_EQ("hello!", response_data); |
| 15571 | |
| 15572 | HttpRequestInfo request2; |
| 15573 | request2.method = "GET"; |
| 15574 | request2.url = GURL("https://mail.example.org/"); |
| 15575 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15576 | request2.traffic_annotation = |
| 15577 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15578 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 15579 | |
| 15580 | BoundTestNetLog log; |
| 15581 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 15582 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15583 | rv = callback.WaitForResult(); |
| 15584 | EXPECT_THAT(rv, IsOk()); |
| 15585 | |
| 15586 | response = trans2.GetResponseInfo(); |
| 15587 | ASSERT_TRUE(response); |
| 15588 | ASSERT_TRUE(response->headers); |
| 15589 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15590 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15591 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15592 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 15593 | EXPECT_EQ("hello!", response_data); |
| 15594 | |
| 15595 | TestNetLogEntry::List entries; |
| 15596 | log.GetEntries(&entries); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15597 | ExpectLogContainsSomewhere( |
| 15598 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15599 | NetLogEventPhase::NONE); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15600 | } |
| 15601 | |
| 15602 | // Test that HTTP 421 responses are properly returned to the caller if received |
| 15603 | // on the retry as well. HttpNetworkTransaction should not infinite loop or lose |
| 15604 | // portions of the response. |
| 15605 | TEST_F(HttpNetworkTransactionTest, ReturnHTTP421OnRetry) { |
| 15606 | // Two hosts resolve to the same IP address. |
| 15607 | const std::string ip_addr = "1.2.3.4"; |
| 15608 | IPAddress ip; |
| 15609 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 15610 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 15611 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15612 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15613 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 15614 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 15615 | |
| 15616 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15617 | |
| 15618 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15619 | spdy::SpdySerializedFrame req1( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15620 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 15621 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15622 | spdy::SpdySerializedFrame req2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15623 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15624 | spdy::SpdySerializedFrame rst( |
| 15625 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15626 | MockWrite writes1[] = { |
| 15627 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 15628 | CreateMockWrite(rst, 6), |
| 15629 | }; |
| 15630 | |
| 15631 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15632 | spdy::SpdySerializedFrame resp1( |
| 15633 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15634 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 15635 | spdy::SpdyHeaderBlock response_headers; |
| 15636 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 15637 | spdy::SpdySerializedFrame resp2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15638 | spdy_util_.ConstructSpdyReply(3, response_headers.Clone())); |
| 15639 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 15640 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 15641 | |
| 15642 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15643 | SequencedSocketData data1(connect1, reads1, writes1); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15644 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15645 | |
| 15646 | AddSSLSocketData(); |
| 15647 | |
| 15648 | // Retry the second request on a second connection. It returns 421 Misdirected |
| 15649 | // Retry again. |
| 15650 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15651 | spdy::SpdySerializedFrame req3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15652 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 15653 | MockWrite writes2[] = { |
| 15654 | CreateMockWrite(req3, 0), |
| 15655 | }; |
| 15656 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15657 | spdy::SpdySerializedFrame resp3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15658 | spdy_util2.ConstructSpdyReply(1, std::move(response_headers))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15659 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15660 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 15661 | MockRead(ASYNC, 0, 3)}; |
| 15662 | |
| 15663 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15664 | SequencedSocketData data2(connect2, reads2, writes2); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15665 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 15666 | |
| 15667 | AddSSLSocketData(); |
| 15668 | |
| 15669 | // Preload mail.example.org into HostCache. |
| 15670 | HostPortPair host_port("mail.example.org", 443); |
| 15671 | HostResolver::RequestInfo resolve_info(host_port); |
| 15672 | AddressList ignored; |
| 15673 | std::unique_ptr<HostResolver::Request> request; |
| 15674 | TestCompletionCallback callback; |
| 15675 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 15676 | &ignored, callback.callback(), |
| 15677 | &request, NetLogWithSource()); |
| 15678 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15679 | rv = callback.WaitForResult(); |
| 15680 | EXPECT_THAT(rv, IsOk()); |
| 15681 | |
| 15682 | HttpRequestInfo request1; |
| 15683 | request1.method = "GET"; |
| 15684 | request1.url = GURL("https://www.example.org/"); |
| 15685 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15686 | request1.traffic_annotation = |
| 15687 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15688 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 15689 | |
| 15690 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 15691 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15692 | rv = callback.WaitForResult(); |
| 15693 | EXPECT_THAT(rv, IsOk()); |
| 15694 | |
| 15695 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 15696 | ASSERT_TRUE(response); |
| 15697 | ASSERT_TRUE(response->headers); |
| 15698 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15699 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15700 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15701 | std::string response_data; |
| 15702 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 15703 | EXPECT_EQ("hello!", response_data); |
| 15704 | |
| 15705 | HttpRequestInfo request2; |
| 15706 | request2.method = "GET"; |
| 15707 | request2.url = GURL("https://mail.example.org/"); |
| 15708 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15709 | request2.traffic_annotation = |
| 15710 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15711 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 15712 | |
| 15713 | BoundTestNetLog log; |
| 15714 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 15715 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15716 | rv = callback.WaitForResult(); |
| 15717 | EXPECT_THAT(rv, IsOk()); |
| 15718 | |
| 15719 | // After a retry, the 421 Misdirected Request is reported back up to the |
| 15720 | // caller. |
| 15721 | response = trans2.GetResponseInfo(); |
| 15722 | ASSERT_TRUE(response); |
| 15723 | ASSERT_TRUE(response->headers); |
| 15724 | EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 15725 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15726 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15727 | EXPECT_TRUE(response->ssl_info.cert); |
| 15728 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 15729 | EXPECT_EQ("hello!", response_data); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15730 | } |
| 15731 | |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 15732 | class OneTimeCachingHostResolver : public MockHostResolverBase { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15733 | public: |
| 15734 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 15735 | : MockHostResolverBase(/* use_caching = */ true), host_port_(host_port) {} |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 15736 | ~OneTimeCachingHostResolver() override = default; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15737 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15738 | int ResolveFromCache(const RequestInfo& info, |
| 15739 | AddressList* addresses, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15740 | const NetLogWithSource& net_log) override { |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 15741 | int rv = MockHostResolverBase::ResolveFromCache(info, addresses, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 15742 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 15743 | GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15744 | return rv; |
| 15745 | } |
| 15746 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15747 | private: |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15748 | const HostPortPair host_port_; |
| 15749 | }; |
| 15750 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15751 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 15752 | UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15753 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15754 | session_deps_.host_resolver = std::make_unique<OneTimeCachingHostResolver>( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15755 | HostPortPair("mail.example.com", 443)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15756 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15757 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15758 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15759 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15760 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15761 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15762 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15763 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15764 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15765 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15766 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15767 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15768 | spdy::SpdySerializedFrame host1_resp( |
| 15769 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 15770 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15771 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15772 | spdy::SpdySerializedFrame host2_resp( |
| 15773 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 15774 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15775 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15776 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15777 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15778 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15779 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15780 | }; |
| 15781 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15782 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15783 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15784 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15785 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15786 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 15787 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15788 | HttpRequestInfo request1; |
| 15789 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15790 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15791 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15792 | request1.traffic_annotation = |
| 15793 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15794 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15795 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15796 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15797 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15798 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15799 | |
| 15800 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15801 | ASSERT_TRUE(response); |
| 15802 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15803 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15804 | |
| 15805 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15806 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15807 | EXPECT_EQ("hello!", response_data); |
| 15808 | |
| 15809 | // Preload cache entries into HostCache. |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15810 | HostResolver::RequestInfo resolve_info(HostPortPair("mail.example.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15811 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 15812 | std::unique_ptr<HostResolver::Request> request; |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 15813 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 15814 | &ignored, callback.callback(), |
| 15815 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15816 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 15817 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15818 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15819 | |
| 15820 | HttpRequestInfo request2; |
| 15821 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15822 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15823 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15824 | request2.traffic_annotation = |
| 15825 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15826 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15827 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15828 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15829 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15830 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15831 | |
| 15832 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15833 | ASSERT_TRUE(response); |
| 15834 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15835 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15836 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15837 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15838 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15839 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15840 | } |
| 15841 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15842 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15843 | const std::string https_url = "https://www.example.org:8080/"; |
| 15844 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15845 | |
| 15846 | // SPDY GET for HTTPS URL |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15847 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15848 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15849 | |
| 15850 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15851 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15852 | }; |
| 15853 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15854 | spdy::SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 15855 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15856 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15857 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15858 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15859 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15860 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 15861 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15862 | |
| 15863 | // HTTP GET for the HTTP URL |
| 15864 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15865 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15866 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15867 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15868 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15869 | }; |
| 15870 | |
| 15871 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15872 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 15873 | MockRead(ASYNC, 2, "hello"), |
| 15874 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15875 | }; |
| 15876 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15877 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15878 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15879 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15880 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15881 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15882 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15883 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15884 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15885 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15886 | |
| 15887 | // Start the first transaction to set up the SpdySession |
| 15888 | HttpRequestInfo request1; |
| 15889 | request1.method = "GET"; |
| 15890 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15891 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15892 | request1.traffic_annotation = |
| 15893 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15894 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15895 | TestCompletionCallback callback1; |
| 15896 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15897 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15898 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15899 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15900 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15901 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15902 | |
| 15903 | // Now, start the HTTP request |
| 15904 | HttpRequestInfo request2; |
| 15905 | request2.method = "GET"; |
| 15906 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15907 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15908 | request2.traffic_annotation = |
| 15909 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15910 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15911 | TestCompletionCallback callback2; |
| 15912 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15913 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15914 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15915 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15916 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15917 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 15918 | } |
| 15919 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15920 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 15921 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15922 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15923 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 15924 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15925 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15926 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15927 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15928 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15929 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15930 | |
| 15931 | // No data should be read from the alternative, because HTTP/1.1 is |
| 15932 | // negotiated. |
| 15933 | StaticSocketDataProvider data; |
| 15934 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15935 | |
| 15936 | // 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] | 15937 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15938 | // mocked. This way the request relies on the alternate Job. |
| 15939 | StaticSocketDataProvider data_refused; |
| 15940 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 15941 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 15942 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15943 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15944 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 15945 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15946 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 15947 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 15948 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 15949 | http_server_properties->SetHttp2AlternativeService( |
| 15950 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15951 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15952 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15953 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15954 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15955 | request.url = GURL("https://www.example.org:443"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15956 | request.traffic_annotation = |
| 15957 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15958 | TestCompletionCallback callback; |
| 15959 | |
| 15960 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15961 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15962 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15963 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15964 | } |
| 15965 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15966 | // 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] | 15967 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15968 | // succeeds, the request should succeed, even if the latter fails because |
| 15969 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15970 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15971 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 15972 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15973 | |
| 15974 | // Negotiate HTTP/1.1 with alternative. |
| 15975 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15976 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15977 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 15978 | |
| 15979 | // No data should be read from the alternative, because HTTP/1.1 is |
| 15980 | // negotiated. |
| 15981 | StaticSocketDataProvider data; |
| 15982 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15983 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15984 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15985 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15986 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15987 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 15988 | |
| 15989 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15990 | MockWrite("GET / HTTP/1.1\r\n" |
| 15991 | "Host: www.example.org\r\n" |
| 15992 | "Connection: keep-alive\r\n\r\n"), |
| 15993 | MockWrite("GET /second HTTP/1.1\r\n" |
| 15994 | "Host: www.example.org\r\n" |
| 15995 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15996 | }; |
| 15997 | |
| 15998 | MockRead http_reads[] = { |
| 15999 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16000 | MockRead("Content-Type: text/html\r\n"), |
| 16001 | MockRead("Content-Length: 6\r\n\r\n"), |
| 16002 | MockRead("foobar"), |
| 16003 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16004 | MockRead("Content-Type: text/html\r\n"), |
| 16005 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16006 | MockRead("another"), |
| 16007 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16008 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16009 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16010 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16011 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16012 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16013 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16014 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16015 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16016 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16017 | http_server_properties->SetHttp2AlternativeService( |
| 16018 | server, alternative_service, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16019 | |
| 16020 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 16021 | HttpRequestInfo request1; |
| 16022 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16023 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16024 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16025 | request1.traffic_annotation = |
| 16026 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16027 | TestCompletionCallback callback1; |
| 16028 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16029 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16030 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16031 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16032 | |
| 16033 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16034 | ASSERT_TRUE(response1); |
| 16035 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16036 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 16037 | |
| 16038 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16039 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16040 | EXPECT_EQ("foobar", response_data1); |
| 16041 | |
| 16042 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 16043 | // for alternative service. |
| 16044 | EXPECT_TRUE( |
| 16045 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 16046 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16047 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16048 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16049 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16050 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 16051 | HttpRequestInfo request2; |
| 16052 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16053 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16054 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16055 | request2.traffic_annotation = |
| 16056 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16057 | TestCompletionCallback callback2; |
| 16058 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16059 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16060 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16061 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16062 | |
| 16063 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16064 | ASSERT_TRUE(response2); |
| 16065 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16066 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 16067 | |
| 16068 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16069 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16070 | EXPECT_EQ("another", response_data2); |
| 16071 | } |
| 16072 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16073 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 16074 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 16075 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16076 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16077 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16078 | HostPortPair alternative("alternative.example.org", 443); |
| 16079 | std::string origin_url = "https://origin.example.org:443"; |
| 16080 | std::string alternative_url = "https://alternative.example.org:443"; |
| 16081 | |
| 16082 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 16083 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16084 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16085 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16086 | |
| 16087 | // HTTP/1.1 data for |request1| and |request2|. |
| 16088 | MockWrite http_writes[] = { |
| 16089 | MockWrite( |
| 16090 | "GET / HTTP/1.1\r\n" |
| 16091 | "Host: alternative.example.org\r\n" |
| 16092 | "Connection: keep-alive\r\n\r\n"), |
| 16093 | MockWrite( |
| 16094 | "GET / HTTP/1.1\r\n" |
| 16095 | "Host: alternative.example.org\r\n" |
| 16096 | "Connection: keep-alive\r\n\r\n"), |
| 16097 | }; |
| 16098 | |
| 16099 | MockRead http_reads[] = { |
| 16100 | MockRead( |
| 16101 | "HTTP/1.1 200 OK\r\n" |
| 16102 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 16103 | "Content-Length: 40\r\n\r\n" |
| 16104 | "first HTTP/1.1 response from alternative"), |
| 16105 | MockRead( |
| 16106 | "HTTP/1.1 200 OK\r\n" |
| 16107 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 16108 | "Content-Length: 41\r\n\r\n" |
| 16109 | "second HTTP/1.1 response from alternative"), |
| 16110 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16111 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16112 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16113 | |
| 16114 | // This test documents that an alternate Job should not pool to an already |
| 16115 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16116 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16117 | StaticSocketDataProvider data_refused; |
| 16118 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 16119 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 16120 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16121 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16122 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16123 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16124 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16125 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16126 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16127 | http_server_properties->SetHttp2AlternativeService( |
| 16128 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16129 | |
| 16130 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16131 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16132 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16133 | request1.method = "GET"; |
| 16134 | request1.url = GURL(alternative_url); |
| 16135 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16136 | request1.traffic_annotation = |
| 16137 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16138 | TestCompletionCallback callback1; |
| 16139 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16140 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16141 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16142 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16143 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16144 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16145 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16146 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16147 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 16148 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16149 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16150 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 16151 | |
| 16152 | // Request for origin.example.org, which has an alternative service. This |
| 16153 | // will start two Jobs: the alternative looks for connections to pool to, |
| 16154 | // 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] | 16155 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16156 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16157 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16158 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16159 | request2.method = "GET"; |
| 16160 | request2.url = GURL(origin_url); |
| 16161 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16162 | request2.traffic_annotation = |
| 16163 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16164 | TestCompletionCallback callback2; |
| 16165 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16166 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16167 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16168 | |
| 16169 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 16170 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16171 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16172 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16173 | request3.method = "GET"; |
| 16174 | request3.url = GURL(alternative_url); |
| 16175 | request3.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16176 | request3.traffic_annotation = |
| 16177 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16178 | TestCompletionCallback callback3; |
| 16179 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16180 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16181 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16182 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16183 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16184 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16185 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16186 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16187 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 16188 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16189 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16190 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 16191 | } |
| 16192 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16193 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16194 | const std::string https_url = "https://www.example.org:8080/"; |
| 16195 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16196 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16197 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16198 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16199 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16200 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16201 | const HostPortPair host_port_pair("www.example.org", 8080); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16202 | spdy::SpdySerializedFrame connect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 16203 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16204 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16205 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16206 | spdy::SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 16207 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 16208 | |
| 16209 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16210 | spdy::SpdyHeaderBlock req2_block; |
| 16211 | req2_block[spdy::kHttp2MethodHeader] = "GET"; |
| 16212 | req2_block[spdy::kHttp2AuthorityHeader] = "www.example.org:8080"; |
| 16213 | req2_block[spdy::kHttp2SchemeHeader] = "http"; |
| 16214 | req2_block[spdy::kHttp2PathHeader] = "/"; |
| 16215 | spdy::SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16216 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16217 | |
| 16218 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16219 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 16220 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16221 | }; |
| 16222 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16223 | spdy::SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16224 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16225 | spdy::SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16226 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16227 | spdy::SpdySerializedFrame body1( |
| 16228 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 16229 | spdy::SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16230 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16231 | spdy::SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16232 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16233 | spdy::SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 16234 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16235 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16236 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16237 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16238 | CreateMockRead(wrapped_resp1, 4), |
| 16239 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16240 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16241 | CreateMockRead(resp2, 8), |
| 16242 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16243 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 16244 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16245 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16246 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16247 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 16248 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16249 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 16250 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16251 | ProxyResolutionService::CreateFixedFromPacResult( |
| 16252 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 16253 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16254 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16255 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16256 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16257 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16258 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16259 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16260 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16261 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16262 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16263 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16264 | |
| 16265 | // Start the first transaction to set up the SpdySession |
| 16266 | HttpRequestInfo request1; |
| 16267 | request1.method = "GET"; |
| 16268 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16269 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16270 | request1.traffic_annotation = |
| 16271 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16272 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16273 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16274 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16275 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16276 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16277 | data1.RunUntilPaused(); |
| 16278 | base::RunLoop().RunUntilIdle(); |
| 16279 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16280 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16281 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 16282 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 16283 | LoadTimingInfo load_timing_info1; |
| 16284 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 16285 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 16286 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 16287 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16288 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16289 | HttpRequestInfo request2; |
| 16290 | request2.method = "GET"; |
| 16291 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16292 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16293 | request2.traffic_annotation = |
| 16294 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16295 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16296 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16297 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16298 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16299 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16300 | data1.RunUntilPaused(); |
| 16301 | base::RunLoop().RunUntilIdle(); |
| 16302 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16303 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16304 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16305 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 16306 | |
| 16307 | LoadTimingInfo load_timing_info2; |
| 16308 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 16309 | // The established SPDY sessions is considered reused by the HTTP request. |
| 16310 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 16311 | // HTTP requests over a SPDY session should have a different connection |
| 16312 | // socket_log_id than requests over a tunnel. |
| 16313 | 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] | 16314 | } |
| 16315 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16316 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 16317 | // that we do not pool other origins that resolve to the same IP when |
| 16318 | // the certificate does not match the new origin. |
| 16319 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16320 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16321 | const std::string url1 = "http://www.example.org/"; |
| 16322 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16323 | const std::string ip_addr = "1.2.3.4"; |
| 16324 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16325 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16326 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16327 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16328 | // SPDY GET for HTTP URL (through SPDY proxy) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16329 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16330 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16331 | spdy::SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16332 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16333 | |
| 16334 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16335 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16336 | }; |
| 16337 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16338 | spdy::SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 16339 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16340 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16341 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 16342 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16343 | }; |
| 16344 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16345 | SequencedSocketData data1(reads1, writes1); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 16346 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 16347 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16348 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 16349 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16350 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16351 | |
| 16352 | // SPDY GET for HTTPS URL (direct) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16353 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16354 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16355 | |
| 16356 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16357 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16358 | }; |
| 16359 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16360 | spdy::SpdySerializedFrame resp2( |
| 16361 | spdy_util_secure.ConstructSpdyGetReply(NULL, 0, 1)); |
| 16362 | spdy::SpdySerializedFrame body2( |
| 16363 | spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16364 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16365 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16366 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16367 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16368 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16369 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16370 | |
| 16371 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 16372 | // all others direct. |
| 16373 | ProxyConfig proxy_config; |
| 16374 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16375 | session_deps_.proxy_resolution_service = |
| 16376 | std::make_unique<ProxyResolutionService>( |
| 16377 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 16378 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 16379 | nullptr, nullptr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16380 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16381 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16382 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16383 | // Load a valid cert. Note, that this does not need to |
| 16384 | // be valid for proxy because the MockSSLClientSocket does |
| 16385 | // not actually verify it. But SpdySession will use this |
| 16386 | // to see if it is valid for the new origin |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 16387 | ssl1.ssl_info.cert = |
| 16388 | ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 16389 | ASSERT_TRUE(ssl1.ssl_info.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16390 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16391 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16392 | |
| 16393 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16394 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16395 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16396 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16397 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16398 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16399 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16400 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16401 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16402 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16403 | |
| 16404 | // Start the first transaction to set up the SpdySession |
| 16405 | HttpRequestInfo request1; |
| 16406 | request1.method = "GET"; |
| 16407 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16408 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16409 | request1.traffic_annotation = |
| 16410 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16411 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16412 | TestCompletionCallback callback1; |
| 16413 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16414 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16415 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16416 | data1.RunUntilPaused(); |
| 16417 | base::RunLoop().RunUntilIdle(); |
| 16418 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16419 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16420 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16421 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 16422 | |
| 16423 | // Now, start the HTTP request |
| 16424 | HttpRequestInfo request2; |
| 16425 | request2.method = "GET"; |
| 16426 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16427 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16428 | request2.traffic_annotation = |
| 16429 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16430 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16431 | TestCompletionCallback callback2; |
| 16432 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16433 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 16434 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16435 | |
| 16436 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16437 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16438 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 16439 | } |
| 16440 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16441 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 16442 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 16443 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 16444 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16445 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16446 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16447 | |
| 16448 | MockRead reads1[] = { |
| 16449 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 16450 | }; |
| 16451 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16452 | SequencedSocketData data1(reads1, base::span<MockWrite>()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16453 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16454 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16455 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16456 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16457 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16458 | }; |
| 16459 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16460 | spdy::SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 16461 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16462 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16463 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 16464 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16465 | }; |
| 16466 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16467 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16468 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16469 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16470 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16471 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16472 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16473 | |
| 16474 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16475 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16476 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16477 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16478 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16479 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16480 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16481 | |
| 16482 | // Start the first transaction to set up the SpdySession and verify that |
| 16483 | // connection was closed. |
| 16484 | HttpRequestInfo request1; |
| 16485 | request1.method = "GET"; |
| 16486 | request1.url = GURL(https_url); |
| 16487 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16488 | request1.traffic_annotation = |
| 16489 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16490 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16491 | TestCompletionCallback callback1; |
| 16492 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16493 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16494 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16495 | |
| 16496 | // Now, start the second request and make sure it succeeds. |
| 16497 | HttpRequestInfo request2; |
| 16498 | request2.method = "GET"; |
| 16499 | request2.url = GURL(https_url); |
| 16500 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16501 | request2.traffic_annotation = |
| 16502 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16503 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16504 | TestCompletionCallback callback2; |
| 16505 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16506 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16507 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16508 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16509 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 16510 | } |
| 16511 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16512 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16513 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16514 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16515 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16516 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16517 | |
| 16518 | // Use two different hosts with different IPs so they don't get pooled. |
| 16519 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 16520 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16521 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16522 | |
| 16523 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16524 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16525 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16526 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16527 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16528 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16529 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16530 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16531 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16532 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16533 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16534 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16535 | spdy::SpdySerializedFrame host1_resp( |
| 16536 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 16537 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16538 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16539 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16540 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 16541 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16542 | }; |
| 16543 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16544 | // Use a separate test instance for the separate SpdySession that will be |
| 16545 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16546 | SpdyTestUtil spdy_util_2; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16547 | SequencedSocketData spdy1_data(spdy1_reads, spdy1_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 16548 | session_deps_.socket_factory->AddSocketDataProvider(&spdy1_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16549 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16550 | spdy::SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16551 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16552 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16553 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16554 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16555 | spdy::SpdySerializedFrame host2_resp( |
| 16556 | spdy_util_2.ConstructSpdyGetReply(NULL, 0, 1)); |
| 16557 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16558 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16559 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16560 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 16561 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16562 | }; |
| 16563 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16564 | SequencedSocketData spdy2_data(spdy2_reads, spdy2_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 16565 | session_deps_.socket_factory->AddSocketDataProvider(&spdy2_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16566 | |
| 16567 | MockWrite http_write[] = { |
| 16568 | MockWrite("GET / HTTP/1.1\r\n" |
| 16569 | "Host: www.a.com\r\n" |
| 16570 | "Connection: keep-alive\r\n\r\n"), |
| 16571 | }; |
| 16572 | |
| 16573 | MockRead http_read[] = { |
| 16574 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16575 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 16576 | MockRead("Content-Length: 6\r\n\r\n"), |
| 16577 | MockRead("hello!"), |
| 16578 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16579 | StaticSocketDataProvider http_data(http_read, http_write); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16580 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16581 | |
| 16582 | HostPortPair host_port_pair_a("www.a.com", 443); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16583 | SpdySessionKey spdy_session_key_a( |
| 16584 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16585 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16586 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16587 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16588 | |
| 16589 | TestCompletionCallback callback; |
| 16590 | HttpRequestInfo request1; |
| 16591 | request1.method = "GET"; |
| 16592 | request1.url = GURL("https://www.a.com/"); |
| 16593 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16594 | request1.traffic_annotation = |
| 16595 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16596 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16597 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16598 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16599 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16600 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16601 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16602 | |
| 16603 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16604 | ASSERT_TRUE(response); |
| 16605 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16606 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16607 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16608 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16609 | |
| 16610 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16611 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16612 | EXPECT_EQ("hello!", response_data); |
| 16613 | trans.reset(); |
| 16614 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16615 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16616 | |
| 16617 | HostPortPair host_port_pair_b("www.b.com", 443); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16618 | SpdySessionKey spdy_session_key_b( |
| 16619 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16620 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16621 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16622 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16623 | HttpRequestInfo request2; |
| 16624 | request2.method = "GET"; |
| 16625 | request2.url = GURL("https://www.b.com/"); |
| 16626 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16627 | request2.traffic_annotation = |
| 16628 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16629 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16630 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16631 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16632 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16633 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16634 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16635 | |
| 16636 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16637 | ASSERT_TRUE(response); |
| 16638 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16639 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16640 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16641 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16642 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16643 | EXPECT_EQ("hello!", response_data); |
| 16644 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16645 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16646 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16647 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16648 | |
| 16649 | HostPortPair host_port_pair_a1("www.a.com", 80); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16650 | SpdySessionKey spdy_session_key_a1( |
| 16651 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16652 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16653 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16654 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16655 | HttpRequestInfo request3; |
| 16656 | request3.method = "GET"; |
| 16657 | request3.url = GURL("http://www.a.com/"); |
| 16658 | request3.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16659 | request3.traffic_annotation = |
| 16660 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16661 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16662 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16663 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16664 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16665 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16666 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16667 | |
| 16668 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16669 | ASSERT_TRUE(response); |
| 16670 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16671 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 16672 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16673 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16674 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16675 | EXPECT_EQ("hello!", response_data); |
| 16676 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16677 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16678 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16679 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16680 | } |
| 16681 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16682 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16683 | HttpRequestInfo request; |
| 16684 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16685 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16686 | request.traffic_annotation = |
| 16687 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16688 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16689 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16690 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16691 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16692 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16693 | StaticSocketDataProvider data; |
| 16694 | data.set_connect_data(mock_connect); |
| 16695 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16696 | |
| 16697 | TestCompletionCallback callback; |
| 16698 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16699 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16700 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16701 | |
| 16702 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16703 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16704 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16705 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 16706 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16707 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16708 | |
| 16709 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16710 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16711 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16712 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16713 | |
| 16714 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16715 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16716 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16717 | } |
| 16718 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16719 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16720 | HttpRequestInfo request; |
| 16721 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16722 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16723 | request.traffic_annotation = |
| 16724 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16725 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16726 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16727 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16728 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16729 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16730 | StaticSocketDataProvider data; |
| 16731 | data.set_connect_data(mock_connect); |
| 16732 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16733 | |
| 16734 | TestCompletionCallback callback; |
| 16735 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16736 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16737 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16738 | |
| 16739 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16740 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16741 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16742 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 16743 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16744 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16745 | |
| 16746 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16747 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16748 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16749 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16750 | |
| 16751 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16752 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16753 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16754 | } |
| 16755 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16756 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16757 | HttpRequestInfo request; |
| 16758 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16759 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16760 | request.traffic_annotation = |
| 16761 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16762 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16763 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16764 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16765 | |
| 16766 | MockWrite data_writes[] = { |
| 16767 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16768 | }; |
| 16769 | MockRead data_reads[] = { |
| 16770 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 16771 | }; |
| 16772 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16773 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16774 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16775 | |
| 16776 | TestCompletionCallback callback; |
| 16777 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16778 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16779 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16780 | |
| 16781 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16782 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16783 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16784 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16785 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16786 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16787 | } |
| 16788 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16789 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16790 | HttpRequestInfo request; |
| 16791 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16792 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16793 | request.traffic_annotation = |
| 16794 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16795 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16796 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16797 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16798 | |
| 16799 | MockWrite data_writes[] = { |
| 16800 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 16801 | }; |
| 16802 | MockRead data_reads[] = { |
| 16803 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 16804 | }; |
| 16805 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16806 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16807 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16808 | |
| 16809 | TestCompletionCallback callback; |
| 16810 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16811 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16812 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16813 | |
| 16814 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16815 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16816 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16817 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16818 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16819 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16820 | } |
| 16821 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16822 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16823 | HttpRequestInfo request; |
| 16824 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16825 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16826 | request.traffic_annotation = |
| 16827 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16828 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16829 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16830 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16831 | |
| 16832 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16833 | MockWrite( |
| 16834 | "GET / HTTP/1.1\r\n" |
| 16835 | "Host: www.example.org\r\n" |
| 16836 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16837 | }; |
| 16838 | MockRead data_reads[] = { |
| 16839 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16840 | }; |
| 16841 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16842 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16843 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16844 | |
| 16845 | TestCompletionCallback callback; |
| 16846 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16847 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16848 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16849 | |
| 16850 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16851 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16852 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16853 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16854 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16855 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16856 | } |
| 16857 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16858 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16859 | HttpRequestInfo request; |
| 16860 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16861 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16862 | request.traffic_annotation = |
| 16863 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16864 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16865 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16866 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16867 | |
| 16868 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16869 | MockWrite( |
| 16870 | "GET / HTTP/1.1\r\n" |
| 16871 | "Host: www.example.org\r\n" |
| 16872 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16873 | }; |
| 16874 | MockRead data_reads[] = { |
| 16875 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 16876 | }; |
| 16877 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16878 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16879 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16880 | |
| 16881 | TestCompletionCallback callback; |
| 16882 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16883 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16884 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16885 | |
| 16886 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16887 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16888 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16889 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16890 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16891 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16892 | } |
| 16893 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16894 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16895 | HttpRequestInfo request; |
| 16896 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16897 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16898 | request.extra_headers.SetHeader("X-Foo", "bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16899 | request.traffic_annotation = |
| 16900 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16901 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16902 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16903 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16904 | |
| 16905 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16906 | MockWrite( |
| 16907 | "GET / HTTP/1.1\r\n" |
| 16908 | "Host: www.example.org\r\n" |
| 16909 | "Connection: keep-alive\r\n" |
| 16910 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16911 | }; |
| 16912 | MockRead data_reads[] = { |
| 16913 | MockRead("HTTP/1.1 200 OK\r\n" |
| 16914 | "Content-Length: 5\r\n\r\n" |
| 16915 | "hello"), |
| 16916 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 16917 | }; |
| 16918 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16919 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16920 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16921 | |
| 16922 | TestCompletionCallback callback; |
| 16923 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16924 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16925 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16926 | |
| 16927 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16928 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16929 | |
| 16930 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16931 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16932 | std::string foo; |
| 16933 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 16934 | EXPECT_EQ("bar", foo); |
| 16935 | } |
| 16936 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16937 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 16938 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16939 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16940 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16941 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16942 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16943 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16944 | |
| 16945 | // Set up SSL request. |
| 16946 | |
| 16947 | HttpRequestInfo ssl_request; |
| 16948 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16949 | ssl_request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16950 | ssl_request.traffic_annotation = |
| 16951 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16952 | |
| 16953 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16954 | MockWrite( |
| 16955 | "GET / HTTP/1.1\r\n" |
| 16956 | "Host: www.example.org\r\n" |
| 16957 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16958 | }; |
| 16959 | MockRead ssl_reads[] = { |
| 16960 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16961 | MockRead("Content-Length: 11\r\n\r\n"), |
| 16962 | MockRead("hello world"), |
| 16963 | MockRead(SYNCHRONOUS, OK), |
| 16964 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16965 | StaticSocketDataProvider ssl_data(ssl_reads, ssl_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16966 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 16967 | |
| 16968 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16969 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16970 | |
| 16971 | // Set up HTTP request. |
| 16972 | |
| 16973 | HttpRequestInfo http_request; |
| 16974 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16975 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16976 | http_request.traffic_annotation = |
| 16977 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16978 | |
| 16979 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16980 | MockWrite( |
| 16981 | "GET / HTTP/1.1\r\n" |
| 16982 | "Host: www.example.org\r\n" |
| 16983 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16984 | }; |
| 16985 | MockRead http_reads[] = { |
| 16986 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16987 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16988 | MockRead("falafel"), |
| 16989 | MockRead(SYNCHRONOUS, OK), |
| 16990 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16991 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16992 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16993 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16994 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16995 | |
| 16996 | // Start the SSL request. |
| 16997 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16998 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16999 | ASSERT_EQ(ERR_IO_PENDING, |
| 17000 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 17001 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17002 | |
| 17003 | // Start the HTTP request. Pool should stall. |
| 17004 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17005 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17006 | ASSERT_EQ(ERR_IO_PENDING, |
| 17007 | http_trans.Start(&http_request, http_callback.callback(), |
| 17008 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17009 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17010 | |
| 17011 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17012 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17013 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17014 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17015 | EXPECT_EQ("hello world", response_data); |
| 17016 | |
| 17017 | // The SSL socket should automatically be closed, so the HTTP request can |
| 17018 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17019 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 17020 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17021 | |
| 17022 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17023 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17024 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17025 | EXPECT_EQ("falafel", response_data); |
| 17026 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17027 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17028 | } |
| 17029 | |
| 17030 | // Tests that when a SSL connection is established but there's no corresponding |
| 17031 | // request that needs it, the new socket is closed if the transport socket pool |
| 17032 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17033 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17034 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 17035 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17036 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 17037 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17038 | |
| 17039 | // Set up an ssl request. |
| 17040 | |
| 17041 | HttpRequestInfo ssl_request; |
| 17042 | ssl_request.method = "GET"; |
| 17043 | ssl_request.url = GURL("https://www.foopy.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17044 | ssl_request.traffic_annotation = |
| 17045 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17046 | |
| 17047 | // No data will be sent on the SSL socket. |
| 17048 | StaticSocketDataProvider ssl_data; |
| 17049 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 17050 | |
| 17051 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17052 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17053 | |
| 17054 | // Set up HTTP request. |
| 17055 | |
| 17056 | HttpRequestInfo http_request; |
| 17057 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17058 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17059 | http_request.traffic_annotation = |
| 17060 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17061 | |
| 17062 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17063 | MockWrite( |
| 17064 | "GET / HTTP/1.1\r\n" |
| 17065 | "Host: www.example.org\r\n" |
| 17066 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17067 | }; |
| 17068 | MockRead http_reads[] = { |
| 17069 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17070 | MockRead("Content-Length: 7\r\n\r\n"), |
| 17071 | MockRead("falafel"), |
| 17072 | MockRead(SYNCHRONOUS, OK), |
| 17073 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17074 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17075 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 17076 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17077 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17078 | |
| 17079 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 17080 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 17081 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 17082 | http_stream_factory->PreconnectStreams(1, ssl_request); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17083 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17084 | |
| 17085 | // Start the HTTP request. Pool should stall. |
| 17086 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17087 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17088 | ASSERT_EQ(ERR_IO_PENDING, |
| 17089 | http_trans.Start(&http_request, http_callback.callback(), |
| 17090 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17091 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17092 | |
| 17093 | // The SSL connection will automatically be closed once the connection is |
| 17094 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17095 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17096 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17097 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17098 | EXPECT_EQ("falafel", response_data); |
| 17099 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17100 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17101 | } |
| 17102 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17103 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17104 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17105 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17106 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17107 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17108 | |
| 17109 | HttpRequestInfo request; |
| 17110 | request.method = "POST"; |
| 17111 | request.url = GURL("http://www.foo.com/"); |
| 17112 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17113 | request.traffic_annotation = |
| 17114 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17115 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17116 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17117 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17118 | // Send headers successfully, but get an error while sending the body. |
| 17119 | MockWrite data_writes[] = { |
| 17120 | MockWrite("POST / HTTP/1.1\r\n" |
| 17121 | "Host: www.foo.com\r\n" |
| 17122 | "Connection: keep-alive\r\n" |
| 17123 | "Content-Length: 3\r\n\r\n"), |
| 17124 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17125 | }; |
| 17126 | |
| 17127 | MockRead data_reads[] = { |
| 17128 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17129 | MockRead("hello world"), |
| 17130 | MockRead(SYNCHRONOUS, OK), |
| 17131 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17132 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17133 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17134 | |
| 17135 | TestCompletionCallback callback; |
| 17136 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17137 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17138 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17139 | |
| 17140 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17141 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17142 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17143 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17144 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17145 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17146 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17147 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17148 | |
| 17149 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17150 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17151 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17152 | EXPECT_EQ("hello world", response_data); |
| 17153 | } |
| 17154 | |
| 17155 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 17156 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17157 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17158 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17159 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17160 | MockWrite data_writes[] = { |
| 17161 | MockWrite("GET / HTTP/1.1\r\n" |
| 17162 | "Host: www.foo.com\r\n" |
| 17163 | "Connection: keep-alive\r\n\r\n"), |
| 17164 | MockWrite("POST / HTTP/1.1\r\n" |
| 17165 | "Host: www.foo.com\r\n" |
| 17166 | "Connection: keep-alive\r\n" |
| 17167 | "Content-Length: 3\r\n\r\n"), |
| 17168 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17169 | }; |
| 17170 | |
| 17171 | MockRead data_reads[] = { |
| 17172 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 17173 | "Content-Length: 14\r\n\r\n"), |
| 17174 | MockRead("first response"), |
| 17175 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 17176 | "Content-Length: 15\r\n\r\n"), |
| 17177 | MockRead("second response"), |
| 17178 | MockRead(SYNCHRONOUS, OK), |
| 17179 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17180 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17181 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17182 | |
| 17183 | TestCompletionCallback callback; |
| 17184 | HttpRequestInfo request1; |
| 17185 | request1.method = "GET"; |
| 17186 | request1.url = GURL("http://www.foo.com/"); |
| 17187 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17188 | request1.traffic_annotation = |
| 17189 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17190 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17191 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17192 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17193 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17194 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17195 | |
| 17196 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17197 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17198 | |
| 17199 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17200 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17201 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17202 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17203 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 17204 | |
| 17205 | std::string response_data1; |
| 17206 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17207 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17208 | EXPECT_EQ("first response", response_data1); |
| 17209 | // Delete the transaction to release the socket back into the socket pool. |
| 17210 | trans1.reset(); |
| 17211 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17212 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17213 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17214 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17215 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17216 | |
| 17217 | HttpRequestInfo request2; |
| 17218 | request2.method = "POST"; |
| 17219 | request2.url = GURL("http://www.foo.com/"); |
| 17220 | request2.upload_data_stream = &upload_data_stream; |
| 17221 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17222 | request2.traffic_annotation = |
| 17223 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17224 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17225 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17226 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17227 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17228 | |
| 17229 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17230 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17231 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17232 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17233 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17234 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17235 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17236 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 17237 | |
| 17238 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17239 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17240 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17241 | EXPECT_EQ("second response", response_data2); |
| 17242 | } |
| 17243 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17244 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17245 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17246 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17247 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17248 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17249 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17250 | |
| 17251 | HttpRequestInfo request; |
| 17252 | request.method = "POST"; |
| 17253 | request.url = GURL("http://www.foo.com/"); |
| 17254 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17255 | request.traffic_annotation = |
| 17256 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17257 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17258 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17259 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17260 | // Send headers successfully, but get an error while sending the body. |
| 17261 | MockWrite data_writes[] = { |
| 17262 | MockWrite("POST / HTTP/1.1\r\n" |
| 17263 | "Host: www.foo.com\r\n" |
| 17264 | "Connection: keep-alive\r\n" |
| 17265 | "Content-Length: 3\r\n\r\n" |
| 17266 | "fo"), |
| 17267 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17268 | }; |
| 17269 | |
| 17270 | MockRead data_reads[] = { |
| 17271 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17272 | MockRead("hello world"), |
| 17273 | MockRead(SYNCHRONOUS, OK), |
| 17274 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17275 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17276 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17277 | |
| 17278 | TestCompletionCallback callback; |
| 17279 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17280 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17281 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17282 | |
| 17283 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17284 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17285 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17286 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17287 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17288 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17289 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17290 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17291 | |
| 17292 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17293 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17294 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17295 | EXPECT_EQ("hello world", response_data); |
| 17296 | } |
| 17297 | |
| 17298 | // This tests the more common case than the previous test, where headers and |
| 17299 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17300 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 17301 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17302 | |
| 17303 | HttpRequestInfo request; |
| 17304 | request.method = "POST"; |
| 17305 | request.url = GURL("http://www.foo.com/"); |
| 17306 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17307 | request.traffic_annotation = |
| 17308 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17309 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17310 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17311 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17312 | // Send headers successfully, but get an error while sending the body. |
| 17313 | MockWrite data_writes[] = { |
| 17314 | MockWrite("POST / HTTP/1.1\r\n" |
| 17315 | "Host: www.foo.com\r\n" |
| 17316 | "Connection: keep-alive\r\n" |
| 17317 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 17318 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17319 | }; |
| 17320 | |
| 17321 | MockRead data_reads[] = { |
| 17322 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17323 | MockRead("hello world"), |
| 17324 | MockRead(SYNCHRONOUS, OK), |
| 17325 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17326 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17327 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17328 | |
| 17329 | TestCompletionCallback callback; |
| 17330 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17331 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17332 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17333 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 17334 | // they can't be merged with the body in a single send. Not currently |
| 17335 | // necessary since a chunked body is never merged with headers, but this makes |
| 17336 | // the test more future proof. |
| 17337 | base::RunLoop().RunUntilIdle(); |
| 17338 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 17339 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17340 | |
| 17341 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17342 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17343 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17344 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17345 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17346 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17347 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17348 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17349 | |
| 17350 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17351 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17352 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17353 | EXPECT_EQ("hello world", response_data); |
| 17354 | } |
| 17355 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17356 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17357 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17358 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17359 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17360 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17361 | |
| 17362 | HttpRequestInfo request; |
| 17363 | request.method = "POST"; |
| 17364 | request.url = GURL("http://www.foo.com/"); |
| 17365 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17366 | request.traffic_annotation = |
| 17367 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17368 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17369 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17370 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17371 | |
| 17372 | MockWrite data_writes[] = { |
| 17373 | MockWrite("POST / HTTP/1.1\r\n" |
| 17374 | "Host: www.foo.com\r\n" |
| 17375 | "Connection: keep-alive\r\n" |
| 17376 | "Content-Length: 3\r\n\r\n"), |
| 17377 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17378 | }; |
| 17379 | |
| 17380 | MockRead data_reads[] = { |
| 17381 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 17382 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17383 | MockRead("hello world"), |
| 17384 | MockRead(SYNCHRONOUS, OK), |
| 17385 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17386 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17387 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17388 | |
| 17389 | TestCompletionCallback callback; |
| 17390 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17391 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17392 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17393 | |
| 17394 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17395 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17396 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17397 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17398 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17399 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17400 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17401 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17402 | |
| 17403 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17404 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17405 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17406 | EXPECT_EQ("hello world", response_data); |
| 17407 | } |
| 17408 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17409 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17410 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17411 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17412 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17413 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17414 | |
| 17415 | HttpRequestInfo request; |
| 17416 | request.method = "POST"; |
| 17417 | request.url = GURL("http://www.foo.com/"); |
| 17418 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17419 | request.traffic_annotation = |
| 17420 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17421 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17422 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17423 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17424 | // Send headers successfully, but get an error while sending the body. |
| 17425 | MockWrite data_writes[] = { |
| 17426 | MockWrite("POST / HTTP/1.1\r\n" |
| 17427 | "Host: www.foo.com\r\n" |
| 17428 | "Connection: keep-alive\r\n" |
| 17429 | "Content-Length: 3\r\n\r\n"), |
| 17430 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17431 | }; |
| 17432 | |
| 17433 | MockRead data_reads[] = { |
| 17434 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 17435 | MockRead("hello world"), |
| 17436 | MockRead(SYNCHRONOUS, OK), |
| 17437 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17438 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17439 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17440 | |
| 17441 | TestCompletionCallback callback; |
| 17442 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17443 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17444 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17445 | |
| 17446 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17447 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17448 | } |
| 17449 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17450 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17451 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17452 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17453 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17454 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17455 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17456 | |
| 17457 | HttpRequestInfo request; |
| 17458 | request.method = "POST"; |
| 17459 | request.url = GURL("http://www.foo.com/"); |
| 17460 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17461 | request.traffic_annotation = |
| 17462 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17463 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17464 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17465 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17466 | // Send headers successfully, but get an error while sending the body. |
| 17467 | MockWrite data_writes[] = { |
| 17468 | MockWrite("POST / HTTP/1.1\r\n" |
| 17469 | "Host: www.foo.com\r\n" |
| 17470 | "Connection: keep-alive\r\n" |
| 17471 | "Content-Length: 3\r\n\r\n"), |
| 17472 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17473 | }; |
| 17474 | |
| 17475 | MockRead data_reads[] = { |
| 17476 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 17477 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 17478 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 17479 | MockRead("Content-Length: 0\r\n\r\n"), |
| 17480 | MockRead(SYNCHRONOUS, OK), |
| 17481 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17482 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17483 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17484 | |
| 17485 | TestCompletionCallback callback; |
| 17486 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17487 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17488 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17489 | |
| 17490 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17491 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17492 | } |
| 17493 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17494 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17495 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17496 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17497 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17498 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17499 | |
| 17500 | HttpRequestInfo request; |
| 17501 | request.method = "POST"; |
| 17502 | request.url = GURL("http://www.foo.com/"); |
| 17503 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17504 | request.traffic_annotation = |
| 17505 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17506 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17507 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17508 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17509 | // Send headers successfully, but get an error while sending the body. |
| 17510 | MockWrite data_writes[] = { |
| 17511 | MockWrite("POST / HTTP/1.1\r\n" |
| 17512 | "Host: www.foo.com\r\n" |
| 17513 | "Connection: keep-alive\r\n" |
| 17514 | "Content-Length: 3\r\n\r\n"), |
| 17515 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17516 | }; |
| 17517 | |
| 17518 | MockRead data_reads[] = { |
| 17519 | MockRead("HTTP 0.9 rocks!"), |
| 17520 | MockRead(SYNCHRONOUS, OK), |
| 17521 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17522 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17523 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17524 | |
| 17525 | TestCompletionCallback callback; |
| 17526 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17527 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17528 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17529 | |
| 17530 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17531 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17532 | } |
| 17533 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17534 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17535 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17536 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17537 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17538 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17539 | |
| 17540 | HttpRequestInfo request; |
| 17541 | request.method = "POST"; |
| 17542 | request.url = GURL("http://www.foo.com/"); |
| 17543 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17544 | request.traffic_annotation = |
| 17545 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17546 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17547 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17548 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17549 | // Send headers successfully, but get an error while sending the body. |
| 17550 | MockWrite data_writes[] = { |
| 17551 | MockWrite("POST / HTTP/1.1\r\n" |
| 17552 | "Host: www.foo.com\r\n" |
| 17553 | "Connection: keep-alive\r\n" |
| 17554 | "Content-Length: 3\r\n\r\n"), |
| 17555 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17556 | }; |
| 17557 | |
| 17558 | MockRead data_reads[] = { |
| 17559 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 17560 | MockRead(SYNCHRONOUS, OK), |
| 17561 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17562 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17563 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17564 | |
| 17565 | TestCompletionCallback callback; |
| 17566 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17567 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17568 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17569 | |
| 17570 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17571 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17572 | } |
| 17573 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17574 | #if BUILDFLAG(ENABLE_WEBSOCKETS) |
| 17575 | |
| 17576 | namespace { |
| 17577 | |
| 17578 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
| 17579 | headers->SetHeader("Connection", "Upgrade"); |
| 17580 | headers->SetHeader("Upgrade", "websocket"); |
| 17581 | headers->SetHeader("Origin", "http://www.example.org"); |
| 17582 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17583 | } |
| 17584 | |
| 17585 | } // namespace |
| 17586 | |
| 17587 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17588 | for (bool secure : {true, false}) { |
| 17589 | MockWrite data_writes[] = { |
| 17590 | MockWrite("GET / HTTP/1.1\r\n" |
| 17591 | "Host: www.example.org\r\n" |
| 17592 | "Connection: Upgrade\r\n" |
| 17593 | "Upgrade: websocket\r\n" |
| 17594 | "Origin: http://www.example.org\r\n" |
| 17595 | "Sec-WebSocket-Version: 13\r\n" |
| 17596 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17597 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17598 | "client_max_window_bits\r\n\r\n")}; |
| 17599 | |
| 17600 | MockRead data_reads[] = { |
| 17601 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17602 | "Upgrade: websocket\r\n" |
| 17603 | "Connection: Upgrade\r\n" |
| 17604 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
| 17605 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17606 | StaticSocketDataProvider data(data_reads, data_writes); |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17607 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17608 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17609 | if (secure) |
| 17610 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17611 | |
| 17612 | HttpRequestInfo request; |
| 17613 | request.method = "GET"; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17614 | request.url = |
| 17615 | GURL(secure ? "ws://www.example.org/" : "wss://www.example.org/"); |
| 17616 | AddWebSocketHeaders(&request.extra_headers); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17617 | request.traffic_annotation = |
| 17618 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17619 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17620 | TestWebSocketHandshakeStreamCreateHelper |
| 17621 | websocket_handshake_stream_create_helper; |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17622 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17623 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17624 | HttpNetworkTransaction trans(LOW, session.get()); |
| 17625 | trans.SetWebSocketHandshakeStreamCreateHelper( |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17626 | &websocket_handshake_stream_create_helper); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17627 | |
| 17628 | TestCompletionCallback callback; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17629 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17630 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17631 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17632 | const HttpStreamRequest* stream_request = trans.stream_request_.get(); |
| 17633 | ASSERT_TRUE(stream_request); |
| 17634 | EXPECT_EQ(&websocket_handshake_stream_create_helper, |
| 17635 | stream_request->websocket_handshake_stream_create_helper()); |
| 17636 | |
| 17637 | rv = callback.WaitForResult(); |
| 17638 | EXPECT_THAT(rv, IsOk()); |
| 17639 | |
| 17640 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 17641 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17642 | } |
| 17643 | } |
| 17644 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17645 | // Verify that proxy headers are not sent to the destination server when |
| 17646 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17647 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17648 | HttpRequestInfo request; |
| 17649 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17650 | request.url = GURL("wss://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17651 | request.traffic_annotation = |
| 17652 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17653 | AddWebSocketHeaders(&request.extra_headers); |
| 17654 | |
| 17655 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17656 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17657 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17658 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17659 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17660 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17661 | |
| 17662 | // Since a proxy is configured, try to establish a tunnel. |
| 17663 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17664 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 17665 | "Host: www.example.org:443\r\n" |
| 17666 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17667 | |
| 17668 | // After calling trans->RestartWithAuth(), this is the request we should |
| 17669 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17670 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 17671 | "Host: www.example.org:443\r\n" |
| 17672 | "Proxy-Connection: keep-alive\r\n" |
| 17673 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17674 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17675 | MockWrite("GET / HTTP/1.1\r\n" |
| 17676 | "Host: www.example.org\r\n" |
| 17677 | "Connection: Upgrade\r\n" |
| 17678 | "Upgrade: websocket\r\n" |
| 17679 | "Origin: http://www.example.org\r\n" |
| 17680 | "Sec-WebSocket-Version: 13\r\n" |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17681 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17682 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17683 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17684 | |
| 17685 | // The proxy responds to the connect with a 407, using a persistent |
| 17686 | // connection. |
| 17687 | MockRead data_reads[] = { |
| 17688 | // No credentials. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17689 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 17690 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 17691 | "Content-Length: 0\r\n" |
| 17692 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17693 | |
| 17694 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 17695 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17696 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17697 | "Upgrade: websocket\r\n" |
| 17698 | "Connection: Upgrade\r\n" |
| 17699 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17700 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17701 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17702 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17703 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17704 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17705 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17706 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17707 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17708 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17709 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17710 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 17711 | &websocket_stream_create_helper); |
| 17712 | |
| 17713 | { |
| 17714 | TestCompletionCallback callback; |
| 17715 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17716 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17717 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17718 | |
| 17719 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17720 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17721 | } |
| 17722 | |
| 17723 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17724 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17725 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17726 | EXPECT_EQ(407, response->headers->response_code()); |
| 17727 | |
| 17728 | { |
| 17729 | TestCompletionCallback callback; |
| 17730 | |
| 17731 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 17732 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17733 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17734 | |
| 17735 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17736 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17737 | } |
| 17738 | |
| 17739 | response = trans->GetResponseInfo(); |
| 17740 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17741 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17742 | |
| 17743 | EXPECT_EQ(101, response->headers->response_code()); |
| 17744 | |
| 17745 | trans.reset(); |
| 17746 | session->CloseAllConnections(); |
| 17747 | } |
| 17748 | |
| 17749 | // Verify that proxy headers are not sent to the destination server when |
| 17750 | // establishing a tunnel for an insecure WebSocket connection. |
| 17751 | // This requires the authentication info to be injected into the auth cache |
| 17752 | // due to crbug.com/395064 |
| 17753 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17754 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17755 | HttpRequestInfo request; |
| 17756 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17757 | request.url = GURL("ws://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17758 | request.traffic_annotation = |
| 17759 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17760 | AddWebSocketHeaders(&request.extra_headers); |
| 17761 | |
| 17762 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17763 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17764 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17765 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17766 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17767 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17768 | |
| 17769 | MockWrite data_writes[] = { |
| 17770 | // Try to establish a tunnel for the WebSocket connection, with |
| 17771 | // credentials. Because WebSockets have a separate set of socket pools, |
| 17772 | // they cannot and will not use the same TCP/IP connection as the |
| 17773 | // preflight HTTP request. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17774 | MockWrite("CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 17775 | "Host: www.example.org:80\r\n" |
| 17776 | "Proxy-Connection: keep-alive\r\n" |
| 17777 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17778 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17779 | MockWrite("GET / HTTP/1.1\r\n" |
| 17780 | "Host: www.example.org\r\n" |
| 17781 | "Connection: Upgrade\r\n" |
| 17782 | "Upgrade: websocket\r\n" |
| 17783 | "Origin: http://www.example.org\r\n" |
| 17784 | "Sec-WebSocket-Version: 13\r\n" |
| 17785 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17786 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17787 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17788 | |
| 17789 | MockRead data_reads[] = { |
| 17790 | // HTTP CONNECT with credentials. |
| 17791 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 17792 | |
| 17793 | // WebSocket connection established inside tunnel. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17794 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17795 | "Upgrade: websocket\r\n" |
| 17796 | "Connection: Upgrade\r\n" |
| 17797 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17798 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17799 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17800 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17801 | |
| 17802 | session->http_auth_cache()->Add( |
| 17803 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 17804 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 17805 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17806 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17807 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17808 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17809 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17810 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 17811 | &websocket_stream_create_helper); |
| 17812 | |
| 17813 | TestCompletionCallback callback; |
| 17814 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17815 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17816 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17817 | |
| 17818 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17819 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17820 | |
| 17821 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17822 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17823 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17824 | |
| 17825 | EXPECT_EQ(101, response->headers->response_code()); |
| 17826 | |
| 17827 | trans.reset(); |
| 17828 | session->CloseAllConnections(); |
| 17829 | } |
| 17830 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17831 | #endif // BUILDFLAG(ENABLE_WEBSOCKETS) |
| 17832 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17833 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17834 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17835 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17836 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17837 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17838 | |
| 17839 | HttpRequestInfo request; |
| 17840 | request.method = "POST"; |
| 17841 | request.url = GURL("http://www.foo.com/"); |
| 17842 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17843 | request.traffic_annotation = |
| 17844 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17845 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17846 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17847 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17848 | MockWrite data_writes[] = { |
| 17849 | MockWrite("POST / HTTP/1.1\r\n" |
| 17850 | "Host: www.foo.com\r\n" |
| 17851 | "Connection: keep-alive\r\n" |
| 17852 | "Content-Length: 3\r\n\r\n"), |
| 17853 | MockWrite("foo"), |
| 17854 | }; |
| 17855 | |
| 17856 | MockRead data_reads[] = { |
| 17857 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17858 | MockRead(SYNCHRONOUS, OK), |
| 17859 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17860 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17861 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17862 | |
| 17863 | TestCompletionCallback callback; |
| 17864 | |
| 17865 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17866 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17867 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17868 | |
| 17869 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17870 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17871 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17872 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 17873 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17874 | } |
| 17875 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17876 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17877 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17878 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17879 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17880 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17881 | |
| 17882 | HttpRequestInfo request; |
| 17883 | request.method = "POST"; |
| 17884 | request.url = GURL("http://www.foo.com/"); |
| 17885 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17886 | request.traffic_annotation = |
| 17887 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17888 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17889 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17890 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17891 | MockWrite data_writes[] = { |
| 17892 | MockWrite("POST / HTTP/1.1\r\n" |
| 17893 | "Host: www.foo.com\r\n" |
| 17894 | "Connection: keep-alive\r\n" |
| 17895 | "Content-Length: 3\r\n\r\n"), |
| 17896 | MockWrite("foo"), |
| 17897 | }; |
| 17898 | |
| 17899 | MockRead data_reads[] = { |
| 17900 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 17901 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17902 | MockRead(SYNCHRONOUS, OK), |
| 17903 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17904 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17905 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17906 | |
| 17907 | TestCompletionCallback callback; |
| 17908 | |
| 17909 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17910 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17911 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17912 | |
| 17913 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17914 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17915 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17916 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 17917 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17918 | } |
| 17919 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17920 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17921 | ChunkedUploadDataStream upload_data_stream(0); |
| 17922 | |
| 17923 | HttpRequestInfo request; |
| 17924 | request.method = "POST"; |
| 17925 | request.url = GURL("http://www.foo.com/"); |
| 17926 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17927 | request.traffic_annotation = |
| 17928 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17929 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17930 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17931 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17932 | // Send headers successfully, but get an error while sending the body. |
| 17933 | MockWrite data_writes[] = { |
| 17934 | MockWrite("POST / HTTP/1.1\r\n" |
| 17935 | "Host: www.foo.com\r\n" |
| 17936 | "Connection: keep-alive\r\n" |
| 17937 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 17938 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 17939 | }; |
| 17940 | |
| 17941 | MockRead data_reads[] = { |
| 17942 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17943 | MockRead(SYNCHRONOUS, OK), |
| 17944 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17945 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17946 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17947 | |
| 17948 | TestCompletionCallback callback; |
| 17949 | |
| 17950 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17951 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17952 | |
| 17953 | base::RunLoop().RunUntilIdle(); |
| 17954 | upload_data_stream.AppendData("f", 1, false); |
| 17955 | |
| 17956 | base::RunLoop().RunUntilIdle(); |
| 17957 | upload_data_stream.AppendData("oo", 2, true); |
| 17958 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17959 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17960 | |
| 17961 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17962 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17963 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17964 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 17965 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17966 | } |
| 17967 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17968 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 17969 | const std::string& accept_encoding, |
| 17970 | const std::string& content_encoding, |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17971 | const std::string& location, |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17972 | bool should_match) { |
| 17973 | HttpRequestInfo request; |
| 17974 | request.method = "GET"; |
| 17975 | request.url = GURL("http://www.foo.com/"); |
| 17976 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 17977 | accept_encoding); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17978 | request.traffic_annotation = |
| 17979 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17980 | |
| 17981 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 17982 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17983 | // Send headers successfully, but get an error while sending the body. |
| 17984 | MockWrite data_writes[] = { |
| 17985 | MockWrite("GET / HTTP/1.1\r\n" |
| 17986 | "Host: www.foo.com\r\n" |
| 17987 | "Connection: keep-alive\r\n" |
| 17988 | "Accept-Encoding: "), |
| 17989 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 17990 | }; |
| 17991 | |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17992 | std::string response_code = "200 OK"; |
| 17993 | std::string extra; |
| 17994 | if (!location.empty()) { |
| 17995 | response_code = "301 Redirect\r\nLocation: "; |
| 17996 | response_code.append(location); |
| 17997 | } |
| 17998 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17999 | MockRead data_reads[] = { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18000 | MockRead("HTTP/1.0 "), |
| 18001 | MockRead(response_code.data()), |
| 18002 | MockRead("\r\nContent-Encoding: "), |
| 18003 | MockRead(content_encoding.data()), |
| 18004 | MockRead("\r\n\r\n"), |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18005 | MockRead(SYNCHRONOUS, OK), |
| 18006 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18007 | StaticSocketDataProvider data(data_reads, data_writes); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18008 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 18009 | |
| 18010 | TestCompletionCallback callback; |
| 18011 | |
| 18012 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18013 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18014 | |
| 18015 | rv = callback.WaitForResult(); |
| 18016 | if (should_match) { |
| 18017 | EXPECT_THAT(rv, IsOk()); |
| 18018 | } else { |
| 18019 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 18020 | } |
| 18021 | } |
| 18022 | |
| 18023 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18024 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18025 | } |
| 18026 | |
| 18027 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18028 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", |
| 18029 | true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18030 | } |
| 18031 | |
| 18032 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 18033 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18034 | "", false); |
| 18035 | } |
| 18036 | |
| 18037 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 18038 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 18039 | "www.foo.com/other", true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18040 | } |
| 18041 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18042 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) { |
| 18043 | ProxyConfig proxy_config; |
| 18044 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 18045 | proxy_config.set_pac_mandatory(true); |
| 18046 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18047 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18048 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 18049 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Bence Béky | 8f9d7d395 | 2017-10-09 19:58:04 | [diff] [blame] | 18050 | std::make_unique<FailingProxyResolverFactory>(), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18051 | |
| 18052 | HttpRequestInfo request; |
| 18053 | request.method = "GET"; |
| 18054 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18055 | request.traffic_annotation = |
| 18056 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18057 | |
| 18058 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18059 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18060 | |
| 18061 | TestCompletionCallback callback; |
| 18062 | |
| 18063 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18064 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18065 | EXPECT_THAT(callback.WaitForResult(), |
| 18066 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 18067 | } |
| 18068 | |
| 18069 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) { |
| 18070 | ProxyConfig proxy_config; |
| 18071 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 18072 | proxy_config.set_pac_mandatory(true); |
| 18073 | MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 18074 | new MockAsyncProxyResolverFactory(false); |
| 18075 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18076 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18077 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 18078 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18079 | base::WrapUnique(proxy_resolver_factory), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18080 | HttpRequestInfo request; |
| 18081 | request.method = "GET"; |
| 18082 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18083 | request.traffic_annotation = |
| 18084 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18085 | |
| 18086 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18087 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18088 | |
| 18089 | TestCompletionCallback callback; |
| 18090 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18091 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18092 | |
| 18093 | proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 18094 | ERR_FAILED, &resolver); |
| 18095 | EXPECT_THAT(callback.WaitForResult(), |
| 18096 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 18097 | } |
| 18098 | |
| 18099 | TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18100 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18101 | ProxyResolutionService::CreateFixedFromPacResult( |
| 18102 | "QUIC myproxy.org:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18103 | session_deps_.enable_quic = false; |
| 18104 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18105 | |
| 18106 | HttpRequestInfo request; |
| 18107 | request.method = "GET"; |
| 18108 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18109 | request.traffic_annotation = |
| 18110 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18111 | |
| 18112 | TestCompletionCallback callback; |
| 18113 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18114 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18115 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18116 | |
| 18117 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 18118 | } |
| 18119 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18120 | //----------------------------------------------------------------------------- |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18121 | // Reporting tests |
| 18122 | |
| 18123 | #if BUILDFLAG(ENABLE_REPORTING) |
| 18124 | class HttpNetworkTransactionReportingTest : public HttpNetworkTransactionTest { |
| 18125 | protected: |
| 18126 | void SetUp() override { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18127 | HttpNetworkTransactionTest::SetUp(); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18128 | auto test_reporting_context = std::make_unique<TestReportingContext>( |
| 18129 | &clock_, &tick_clock_, ReportingPolicy()); |
| 18130 | test_reporting_context_ = test_reporting_context.get(); |
| 18131 | session_deps_.reporting_service = |
| 18132 | ReportingService::CreateForTesting(std::move(test_reporting_context)); |
| 18133 | } |
| 18134 | |
| 18135 | TestReportingContext* reporting_context() const { |
| 18136 | return test_reporting_context_; |
| 18137 | } |
| 18138 | |
| 18139 | void clear_reporting_service() { |
| 18140 | session_deps_.reporting_service.reset(); |
| 18141 | test_reporting_context_ = nullptr; |
| 18142 | } |
| 18143 | |
| 18144 | // Makes an HTTPS request that should install a valid Reporting policy. |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18145 | void RequestPolicy(CertStatus cert_status = 0) { |
| 18146 | HttpRequestInfo request; |
| 18147 | request.method = "GET"; |
| 18148 | request.url = GURL(url_); |
| 18149 | request.traffic_annotation = |
| 18150 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18151 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18152 | MockRead data_reads[] = { |
| 18153 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18154 | MockRead("Report-To: {\"group\": \"nel\", \"max_age\": 86400, " |
| 18155 | "\"endpoints\": [{\"url\": " |
| 18156 | "\"https://www.example.org/upload/\"}]}\r\n"), |
| 18157 | MockRead("\r\n"), |
| 18158 | MockRead("hello world"), |
| 18159 | MockRead(SYNCHRONOUS, OK), |
| 18160 | }; |
| 18161 | MockWrite data_writes[] = { |
| 18162 | MockWrite("GET / HTTP/1.1\r\n" |
| 18163 | "Host: www.example.org\r\n" |
| 18164 | "Connection: keep-alive\r\n\r\n"), |
| 18165 | }; |
| 18166 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18167 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18168 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18169 | |
| 18170 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18171 | if (request.url.SchemeIsCryptographic()) { |
| 18172 | ssl.ssl_info.cert = |
| 18173 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18174 | ASSERT_TRUE(ssl.ssl_info.cert); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18175 | ssl.ssl_info.cert_status = cert_status; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18176 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18177 | } |
| 18178 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18179 | TestCompletionCallback callback; |
| 18180 | auto session = CreateSession(&session_deps_); |
| 18181 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18182 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18183 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18184 | } |
| 18185 | |
| 18186 | protected: |
| 18187 | std::string url_ = "https://www.example.org/"; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18188 | |
| 18189 | private: |
| 18190 | TestReportingContext* test_reporting_context_; |
| 18191 | }; |
| 18192 | |
| 18193 | TEST_F(HttpNetworkTransactionReportingTest, |
| 18194 | DontProcessReportToHeaderNoService) { |
| 18195 | base::HistogramTester histograms; |
| 18196 | clear_reporting_service(); |
| 18197 | RequestPolicy(); |
| 18198 | histograms.ExpectBucketCount( |
| 18199 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18200 | ReportingHeaderParser::HeaderOutcome::DISCARDED_NO_REPORTING_SERVICE, 1); |
| 18201 | } |
| 18202 | |
| 18203 | TEST_F(HttpNetworkTransactionReportingTest, DontProcessReportToHeaderHttp) { |
| 18204 | base::HistogramTester histograms; |
| 18205 | url_ = "http://www.example.org/"; |
| 18206 | RequestPolicy(); |
| 18207 | histograms.ExpectBucketCount( |
| 18208 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18209 | ReportingHeaderParser::HeaderOutcome::DISCARDED_INVALID_SSL_INFO, 1); |
| 18210 | } |
| 18211 | |
| 18212 | TEST_F(HttpNetworkTransactionReportingTest, ProcessReportToHeaderHttps) { |
| 18213 | RequestPolicy(); |
| 18214 | std::vector<const ReportingClient*> clients; |
| 18215 | reporting_context()->cache()->GetClients(&clients); |
| 18216 | ASSERT_EQ(1u, clients.size()); |
| 18217 | const auto* client = clients[0]; |
| 18218 | EXPECT_EQ(url::Origin::Create(GURL("https://www.example.org/")), |
| 18219 | client->origin); |
| 18220 | EXPECT_EQ(GURL("https://www.example.org/upload/"), client->endpoint); |
| 18221 | EXPECT_EQ("nel", client->group); |
| 18222 | } |
| 18223 | |
| 18224 | TEST_F(HttpNetworkTransactionReportingTest, |
| 18225 | DontProcessReportToHeaderInvalidHttps) { |
| 18226 | base::HistogramTester histograms; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18227 | CertStatus cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 18228 | RequestPolicy(cert_status); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18229 | histograms.ExpectBucketCount( |
| 18230 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18231 | ReportingHeaderParser::HeaderOutcome::DISCARDED_CERT_STATUS_ERROR, 1); |
| 18232 | } |
| 18233 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 18234 | |
| 18235 | //----------------------------------------------------------------------------- |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18236 | // Network Error Logging tests |
| 18237 | |
| 18238 | #if BUILDFLAG(ENABLE_REPORTING) |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18239 | namespace { |
| 18240 | |
| 18241 | const char kUserAgent[] = "Mozilla/1.0"; |
| 18242 | const char kReferrer[] = "https://www.referrer.org/"; |
| 18243 | |
| 18244 | } // namespace |
| 18245 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18246 | class HttpNetworkTransactionNetworkErrorLoggingTest |
| 18247 | : public HttpNetworkTransactionTest { |
| 18248 | protected: |
| 18249 | void SetUp() override { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18250 | HttpNetworkTransactionTest::SetUp(); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18251 | auto network_error_logging_service = |
| 18252 | std::make_unique<TestNetworkErrorLoggingService>(); |
| 18253 | test_network_error_logging_service_ = network_error_logging_service.get(); |
| 18254 | session_deps_.network_error_logging_service = |
| 18255 | std::move(network_error_logging_service); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18256 | |
| 18257 | extra_headers_.SetHeader("User-Agent", kUserAgent); |
| 18258 | extra_headers_.SetHeader("Referer", kReferrer); |
| 18259 | |
| 18260 | request_.method = "GET"; |
| 18261 | request_.url = GURL(url_); |
| 18262 | request_.extra_headers = extra_headers_; |
| 18263 | request_.reporting_upload_depth = reporting_upload_depth_; |
| 18264 | request_.traffic_annotation = |
| 18265 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18266 | } |
| 18267 | |
| 18268 | TestNetworkErrorLoggingService* network_error_logging_service() const { |
| 18269 | return test_network_error_logging_service_; |
| 18270 | } |
| 18271 | |
| 18272 | void clear_network_error_logging_service() { |
| 18273 | session_deps_.network_error_logging_service.reset(); |
| 18274 | test_network_error_logging_service_ = nullptr; |
| 18275 | } |
| 18276 | |
| 18277 | // Makes an HTTPS request that should install a valid NEL policy. |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18278 | void RequestPolicy(CertStatus cert_status = 0) { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18279 | std::string extra_header_string = extra_headers_.ToString(); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18280 | MockRead data_reads[] = { |
| 18281 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18282 | MockRead("NEL: {\"report_to\": \"nel\", \"max_age\": 86400}\r\n"), |
| 18283 | MockRead("\r\n"), |
| 18284 | MockRead("hello world"), |
| 18285 | MockRead(SYNCHRONOUS, OK), |
| 18286 | }; |
| 18287 | MockWrite data_writes[] = { |
| 18288 | MockWrite("GET / HTTP/1.1\r\n" |
| 18289 | "Host: www.example.org\r\n" |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18290 | "Connection: keep-alive\r\n"), |
| 18291 | MockWrite(ASYNC, extra_header_string.data(), |
| 18292 | extra_header_string.size()), |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18293 | }; |
| 18294 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18295 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18296 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18297 | |
| 18298 | SSLSocketDataProvider ssl(ASYNC, OK); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18299 | if (request_.url.SchemeIsCryptographic()) { |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18300 | ssl.ssl_info.cert = |
| 18301 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18302 | ASSERT_TRUE(ssl.ssl_info.cert); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18303 | ssl.ssl_info.cert_status = cert_status; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18304 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18305 | } |
| 18306 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18307 | TestCompletionCallback callback; |
| 18308 | auto session = CreateSession(&session_deps_); |
| 18309 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18310 | int rv = trans.Start(&request_, callback.callback(), NetLogWithSource()); |
| 18311 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18312 | |
| 18313 | std::string response_data; |
| 18314 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 18315 | EXPECT_EQ("hello world", response_data); |
| 18316 | } |
| 18317 | |
| 18318 | void CheckReport(size_t index, |
| 18319 | int status_code, |
| 18320 | int error_type, |
| 18321 | IPAddress server_ip = IPAddress::IPv4Localhost()) { |
| 18322 | ASSERT_LT(index, network_error_logging_service()->errors().size()); |
| 18323 | |
| 18324 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18325 | network_error_logging_service()->errors()[index]; |
| 18326 | EXPECT_EQ(url_, error.uri); |
| 18327 | EXPECT_EQ(kReferrer, error.referrer); |
| 18328 | EXPECT_EQ(kUserAgent, error.user_agent); |
| 18329 | EXPECT_EQ(server_ip, error.server_ip); |
| 18330 | EXPECT_EQ("http/1.1", error.protocol); |
| 18331 | EXPECT_EQ("GET", error.method); |
| 18332 | EXPECT_EQ(status_code, error.status_code); |
| 18333 | EXPECT_EQ(error_type, error.type); |
| 18334 | EXPECT_EQ(0, error.reporting_upload_depth); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18335 | } |
| 18336 | |
| 18337 | protected: |
| 18338 | std::string url_ = "https://www.example.org/"; |
| 18339 | CertStatus cert_status_ = 0; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18340 | HttpRequestInfo request_; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18341 | HttpRequestHeaders extra_headers_; |
| 18342 | int reporting_upload_depth_ = 0; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18343 | |
| 18344 | private: |
| 18345 | TestNetworkErrorLoggingService* test_network_error_logging_service_; |
| 18346 | }; |
| 18347 | |
| 18348 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18349 | DontProcessNelHeaderNoService) { |
| 18350 | base::HistogramTester histograms; |
| 18351 | clear_network_error_logging_service(); |
| 18352 | RequestPolicy(); |
| 18353 | histograms.ExpectBucketCount( |
| 18354 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18355 | NetworkErrorLoggingService::HeaderOutcome:: |
| 18356 | DISCARDED_NO_NETWORK_ERROR_LOGGING_SERVICE, |
| 18357 | 1); |
| 18358 | } |
| 18359 | |
| 18360 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18361 | DontProcessNelHeaderHttp) { |
| 18362 | base::HistogramTester histograms; |
| 18363 | url_ = "http://www.example.org/"; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18364 | request_.url = GURL(url_); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18365 | RequestPolicy(); |
| 18366 | histograms.ExpectBucketCount( |
| 18367 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18368 | NetworkErrorLoggingService::HeaderOutcome::DISCARDED_INVALID_SSL_INFO, 1); |
| 18369 | } |
| 18370 | |
| 18371 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ProcessNelHeaderHttps) { |
| 18372 | RequestPolicy(); |
| 18373 | ASSERT_EQ(1u, network_error_logging_service()->headers().size()); |
| 18374 | const auto& header = network_error_logging_service()->headers()[0]; |
| 18375 | EXPECT_EQ(url::Origin::Create(GURL("https://www.example.org/")), |
| 18376 | header.origin); |
| 18377 | EXPECT_EQ(IPAddress::IPv4Localhost(), header.received_ip_address); |
| 18378 | EXPECT_EQ("{\"report_to\": \"nel\", \"max_age\": 86400}", header.value); |
| 18379 | } |
| 18380 | |
| 18381 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18382 | DontProcessNelHeaderInvalidHttps) { |
| 18383 | base::HistogramTester histograms; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18384 | CertStatus cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 18385 | RequestPolicy(cert_status); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18386 | histograms.ExpectBucketCount( |
| 18387 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18388 | NetworkErrorLoggingService::HeaderOutcome::DISCARDED_CERT_STATUS_ERROR, |
| 18389 | 1); |
| 18390 | } |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18391 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18392 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, CreateReportSuccess) { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18393 | RequestPolicy(); |
| 18394 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18395 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 18396 | } |
| 18397 | |
| 18398 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18399 | CreateReportErrorAfterStart) { |
| 18400 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18401 | auto trans = |
| 18402 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18403 | |
| 18404 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
| 18405 | StaticSocketDataProvider data; |
| 18406 | data.set_connect_data(mock_connect); |
| 18407 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18408 | |
| 18409 | TestCompletionCallback callback; |
| 18410 | |
| 18411 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18412 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NAME_NOT_RESOLVED)); |
| 18413 | |
| 18414 | trans.reset(); |
| 18415 | |
| 18416 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18417 | CheckReport(0 /* index */, 0 /* status_code */, ERR_NAME_NOT_RESOLVED, |
| 18418 | IPAddress() /* server_ip */); |
| 18419 | } |
| 18420 | |
| 18421 | // Same as above except the error is ASYNC |
| 18422 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18423 | CreateReportErrorAfterStartAsync) { |
| 18424 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18425 | auto trans = |
| 18426 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18427 | |
| 18428 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
| 18429 | StaticSocketDataProvider data; |
| 18430 | data.set_connect_data(mock_connect); |
| 18431 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18432 | |
| 18433 | TestCompletionCallback callback; |
| 18434 | |
| 18435 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18436 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NAME_NOT_RESOLVED)); |
| 18437 | |
| 18438 | trans.reset(); |
| 18439 | |
| 18440 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18441 | CheckReport(0 /* index */, 0 /* status_code */, ERR_NAME_NOT_RESOLVED, |
| 18442 | IPAddress() /* server_ip */); |
| 18443 | } |
| 18444 | |
| 18445 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18446 | CreateReportReadBodyError) { |
| 18447 | std::string extra_header_string = extra_headers_.ToString(); |
| 18448 | MockRead data_reads[] = { |
| 18449 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18450 | MockRead("Content-Length: 100\r\n\r\n"), // wrong content length |
| 18451 | MockRead("hello world"), |
| 18452 | MockRead(SYNCHRONOUS, OK), |
| 18453 | }; |
| 18454 | MockWrite data_writes[] = { |
| 18455 | MockWrite("GET / HTTP/1.1\r\n" |
| 18456 | "Host: www.example.org\r\n" |
| 18457 | "Connection: keep-alive\r\n"), |
| 18458 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18459 | }; |
| 18460 | |
| 18461 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18462 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 18463 | |
| 18464 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18465 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18466 | |
| 18467 | // Log start time |
| 18468 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18469 | |
| 18470 | TestCompletionCallback callback; |
| 18471 | auto session = CreateSession(&session_deps_); |
| 18472 | auto trans = |
| 18473 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18474 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18475 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18476 | |
| 18477 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 18478 | ASSERT_TRUE(response); |
| 18479 | |
| 18480 | EXPECT_TRUE(response->headers); |
| 18481 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 18482 | |
| 18483 | std::string response_data; |
| 18484 | rv = ReadTransaction(trans.get(), &response_data); |
| 18485 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
| 18486 | |
| 18487 | trans.reset(); |
| 18488 | |
| 18489 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18490 | |
| 18491 | CheckReport(0 /* index */, 200 /* status_code */, |
| 18492 | ERR_CONTENT_LENGTH_MISMATCH); |
| 18493 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18494 | network_error_logging_service()->errors()[0]; |
| 18495 | EXPECT_LE(error.elapsed_time, base::TimeTicks::Now() - start_time); |
| 18496 | } |
| 18497 | |
| 18498 | // Same as above except the final read is ASYNC. |
| 18499 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18500 | CreateReportReadBodyErrorAsync) { |
| 18501 | std::string extra_header_string = extra_headers_.ToString(); |
| 18502 | MockRead data_reads[] = { |
| 18503 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18504 | MockRead("Content-Length: 100\r\n\r\n"), // wrong content length |
| 18505 | MockRead("hello world"), |
| 18506 | MockRead(ASYNC, OK), |
| 18507 | }; |
| 18508 | MockWrite data_writes[] = { |
| 18509 | MockWrite("GET / HTTP/1.1\r\n" |
| 18510 | "Host: www.example.org\r\n" |
| 18511 | "Connection: keep-alive\r\n"), |
| 18512 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18513 | }; |
| 18514 | |
| 18515 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18516 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 18517 | |
| 18518 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18519 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18520 | |
| 18521 | // Log start time |
| 18522 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18523 | |
| 18524 | TestCompletionCallback callback; |
| 18525 | auto session = CreateSession(&session_deps_); |
| 18526 | auto trans = |
| 18527 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18528 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18529 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18530 | |
| 18531 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 18532 | ASSERT_TRUE(response); |
| 18533 | |
| 18534 | EXPECT_TRUE(response->headers); |
| 18535 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 18536 | |
| 18537 | std::string response_data; |
| 18538 | rv = ReadTransaction(trans.get(), &response_data); |
| 18539 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
| 18540 | |
| 18541 | trans.reset(); |
| 18542 | |
| 18543 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18544 | |
| 18545 | CheckReport(0 /* index */, 200 /* status_code */, |
| 18546 | ERR_CONTENT_LENGTH_MISMATCH); |
| 18547 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18548 | network_error_logging_service()->errors()[0]; |
| 18549 | EXPECT_LE(error.elapsed_time, base::TimeTicks::Now() - start_time); |
| 18550 | } |
| 18551 | |
| 18552 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18553 | CreateReportRestartWithAuth) { |
| 18554 | std::string extra_header_string = extra_headers_.ToString(); |
| 18555 | static const base::TimeDelta kSleepDuration = |
| 18556 | base::TimeDelta::FromMilliseconds(10); |
| 18557 | |
| 18558 | MockWrite data_writes1[] = { |
| 18559 | MockWrite("GET / HTTP/1.1\r\n" |
| 18560 | "Host: www.example.org\r\n" |
| 18561 | "Connection: keep-alive\r\n"), |
| 18562 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18563 | }; |
| 18564 | |
| 18565 | MockRead data_reads1[] = { |
| 18566 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 18567 | // Give a couple authenticate options (only the middle one is actually |
| 18568 | // supported). |
| 18569 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 18570 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 18571 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 18572 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18573 | // Large content-length -- won't matter, as connection will be reset. |
| 18574 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 18575 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 18576 | }; |
| 18577 | |
| 18578 | // After calling trans->RestartWithAuth(), this is the request we should |
| 18579 | // be issuing -- the final header line contains the credentials. |
| 18580 | MockWrite data_writes2[] = { |
| 18581 | MockWrite("GET / HTTP/1.1\r\n" |
| 18582 | "Host: www.example.org\r\n" |
| 18583 | "Connection: keep-alive\r\n" |
| 18584 | "Authorization: Basic Zm9vOmJhcg==\r\n"), |
| 18585 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18586 | }; |
| 18587 | |
| 18588 | // Lastly, the server responds with the actual content. |
| 18589 | MockRead data_reads2[] = { |
| 18590 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 18591 | MockRead("hello world"), |
| 18592 | MockRead(SYNCHRONOUS, OK), |
| 18593 | }; |
| 18594 | |
| 18595 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18596 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 18597 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18598 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18599 | |
| 18600 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 18601 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18602 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 18603 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18604 | |
| 18605 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18606 | base::TimeTicks restart_time; |
| 18607 | |
| 18608 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18609 | auto trans = |
| 18610 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18611 | |
| 18612 | TestCompletionCallback callback1; |
| 18613 | |
| 18614 | int rv = trans->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 18615 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 18616 | |
| 18617 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18618 | |
| 18619 | TestCompletionCallback callback2; |
| 18620 | |
| 18621 | // Wait 10 ms then restart with auth |
| 18622 | FastForwardBy(kSleepDuration); |
| 18623 | restart_time = base::TimeTicks::Now(); |
| 18624 | rv = |
| 18625 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 18626 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 18627 | |
| 18628 | std::string response_data; |
| 18629 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 18630 | EXPECT_EQ("hello world", response_data); |
| 18631 | |
| 18632 | trans.reset(); |
| 18633 | |
| 18634 | // One 401 report for the auth challenge, then a 200 report for the successful |
| 18635 | // retry. Note that we don't report the error draining the body, as the first |
| 18636 | // request already generated a report for the auth challenge. |
| 18637 | ASSERT_EQ(2u, network_error_logging_service()->errors().size()); |
| 18638 | |
| 18639 | // Check error report contents |
| 18640 | CheckReport(0 /* index */, 401 /* status_code */, OK); |
| 18641 | CheckReport(1 /* index */, 200 /* status_code */, OK); |
| 18642 | |
| 18643 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 18644 | network_error_logging_service()->errors()[0]; |
| 18645 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 18646 | network_error_logging_service()->errors()[1]; |
| 18647 | |
| 18648 | // Sanity-check elapsed time values |
| 18649 | EXPECT_EQ(error1.elapsed_time, restart_time - start_time - kSleepDuration); |
| 18650 | // Check that the start time is refreshed when restarting with auth. |
| 18651 | EXPECT_EQ(error2.elapsed_time, base::TimeTicks::Now() - restart_time); |
| 18652 | } |
| 18653 | |
| 18654 | // Same as above, except draining the body before restarting fails |
| 18655 | // asynchronously. |
| 18656 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18657 | CreateReportRestartWithAuthAsync) { |
| 18658 | std::string extra_header_string = extra_headers_.ToString(); |
| 18659 | static const base::TimeDelta kSleepDuration = |
| 18660 | base::TimeDelta::FromMilliseconds(10); |
| 18661 | |
| 18662 | MockWrite data_writes1[] = { |
| 18663 | MockWrite("GET / HTTP/1.1\r\n" |
| 18664 | "Host: www.example.org\r\n" |
| 18665 | "Connection: keep-alive\r\n"), |
| 18666 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18667 | }; |
| 18668 | |
| 18669 | MockRead data_reads1[] = { |
| 18670 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 18671 | // Give a couple authenticate options (only the middle one is actually |
| 18672 | // supported). |
| 18673 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 18674 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 18675 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 18676 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18677 | // Large content-length -- won't matter, as connection will be reset. |
| 18678 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 18679 | MockRead(ASYNC, ERR_FAILED), |
| 18680 | }; |
| 18681 | |
| 18682 | // After calling trans->RestartWithAuth(), this is the request we should |
| 18683 | // be issuing -- the final header line contains the credentials. |
| 18684 | MockWrite data_writes2[] = { |
| 18685 | MockWrite("GET / HTTP/1.1\r\n" |
| 18686 | "Host: www.example.org\r\n" |
| 18687 | "Connection: keep-alive\r\n" |
| 18688 | "Authorization: Basic Zm9vOmJhcg==\r\n"), |
| 18689 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18690 | }; |
| 18691 | |
| 18692 | // Lastly, the server responds with the actual content. |
| 18693 | MockRead data_reads2[] = { |
| 18694 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 18695 | MockRead("hello world"), |
| 18696 | MockRead(SYNCHRONOUS, OK), |
| 18697 | }; |
| 18698 | |
| 18699 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18700 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 18701 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18702 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18703 | |
| 18704 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 18705 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18706 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 18707 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18708 | |
| 18709 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18710 | base::TimeTicks restart_time; |
| 18711 | |
| 18712 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18713 | auto trans = |
| 18714 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18715 | |
| 18716 | TestCompletionCallback callback1; |
| 18717 | |
| 18718 | int rv = trans->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 18719 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 18720 | |
| 18721 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18722 | |
| 18723 | TestCompletionCallback callback2; |
| 18724 | |
| 18725 | // Wait 10 ms then restart with auth |
| 18726 | FastForwardBy(kSleepDuration); |
| 18727 | restart_time = base::TimeTicks::Now(); |
| 18728 | rv = |
| 18729 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 18730 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 18731 | |
| 18732 | std::string response_data; |
| 18733 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 18734 | EXPECT_EQ("hello world", response_data); |
| 18735 | |
| 18736 | trans.reset(); |
| 18737 | |
| 18738 | // One 401 report for the auth challenge, then a 200 report for the successful |
| 18739 | // retry. Note that we don't report the error draining the body, as the first |
| 18740 | // request already generated a report for the auth challenge. |
| 18741 | ASSERT_EQ(2u, network_error_logging_service()->errors().size()); |
| 18742 | |
| 18743 | // Check error report contents |
| 18744 | CheckReport(0 /* index */, 401 /* status_code */, OK); |
| 18745 | CheckReport(1 /* index */, 200 /* status_code */, OK); |
| 18746 | |
| 18747 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 18748 | network_error_logging_service()->errors()[0]; |
| 18749 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 18750 | network_error_logging_service()->errors()[1]; |
| 18751 | |
| 18752 | // Sanity-check elapsed time values |
| 18753 | EXPECT_EQ(error1.elapsed_time, restart_time - start_time - kSleepDuration); |
| 18754 | // Check that the start time is refreshed when restarting with auth. |
| 18755 | EXPECT_EQ(error2.elapsed_time, base::TimeTicks::Now() - restart_time); |
| 18756 | } |
| 18757 | |
| 18758 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18759 | CreateReportRetryKeepAliveConnectionReset) { |
| 18760 | std::string extra_header_string = extra_headers_.ToString(); |
| 18761 | MockWrite data_writes1[] = { |
| 18762 | MockWrite("GET / HTTP/1.1\r\n" |
| 18763 | "Host: www.example.org\r\n" |
| 18764 | "Connection: keep-alive\r\n"), |
| 18765 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18766 | MockWrite("GET / HTTP/1.1\r\n" |
| 18767 | "Host: www.example.org\r\n" |
| 18768 | "Connection: keep-alive\r\n"), |
| 18769 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18770 | }; |
| 18771 | |
| 18772 | MockRead data_reads1[] = { |
| 18773 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 18774 | MockRead("hello"), |
| 18775 | // Connection is reset |
| 18776 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 18777 | }; |
| 18778 | |
| 18779 | // Successful retry |
| 18780 | MockRead data_reads2[] = { |
| 18781 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 18782 | MockRead("world"), |
| 18783 | MockRead(ASYNC, OK), |
| 18784 | }; |
| 18785 | |
| 18786 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18787 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
| 18788 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18789 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18790 | |
| 18791 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 18792 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18793 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 18794 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18795 | |
| 18796 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18797 | auto trans1 = |
| 18798 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18799 | |
| 18800 | TestCompletionCallback callback1; |
| 18801 | |
| 18802 | int rv = trans1->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 18803 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 18804 | |
| 18805 | std::string response_data; |
| 18806 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 18807 | EXPECT_EQ("hello", response_data); |
| 18808 | |
| 18809 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18810 | |
| 18811 | auto trans2 = |
| 18812 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18813 | |
| 18814 | TestCompletionCallback callback2; |
| 18815 | |
| 18816 | rv = trans2->Start(&request_, callback2.callback(), NetLogWithSource()); |
| 18817 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 18818 | |
| 18819 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 18820 | EXPECT_EQ("world", response_data); |
| 18821 | |
| 18822 | trans1.reset(); |
| 18823 | trans2.reset(); |
| 18824 | |
| 18825 | // One OK report from first request, then a ERR_CONNECTION_RESET report from |
| 18826 | // the second request, then an OK report from the successful retry. |
| 18827 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 18828 | |
| 18829 | // Check error report contents |
| 18830 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 18831 | CheckReport(1 /* index */, 0 /* status_code */, ERR_CONNECTION_RESET); |
| 18832 | CheckReport(2 /* index */, 200 /* status_code */, OK); |
| 18833 | } |
| 18834 | |
| 18835 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18836 | CreateReportRetryKeepAlive408) { |
| 18837 | std::string extra_header_string = extra_headers_.ToString(); |
| 18838 | MockWrite data_writes1[] = { |
| 18839 | MockWrite("GET / HTTP/1.1\r\n" |
| 18840 | "Host: www.example.org\r\n" |
| 18841 | "Connection: keep-alive\r\n"), |
| 18842 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18843 | MockWrite("GET / HTTP/1.1\r\n" |
| 18844 | "Host: www.example.org\r\n" |
| 18845 | "Connection: keep-alive\r\n"), |
| 18846 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18847 | }; |
| 18848 | |
| 18849 | MockRead data_reads1[] = { |
| 18850 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 18851 | MockRead("hello"), |
| 18852 | // 408 Request Timeout |
| 18853 | MockRead(SYNCHRONOUS, |
| 18854 | "HTTP/1.1 408 Request Timeout\r\n" |
| 18855 | "Connection: Keep-Alive\r\n" |
| 18856 | "Content-Length: 6\r\n\r\n" |
| 18857 | "Pickle"), |
| 18858 | }; |
| 18859 | |
| 18860 | // Successful retry |
| 18861 | MockRead data_reads2[] = { |
| 18862 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 18863 | MockRead("world"), |
| 18864 | MockRead(ASYNC, OK), |
| 18865 | }; |
| 18866 | |
| 18867 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18868 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
| 18869 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18870 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18871 | |
| 18872 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 18873 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18874 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 18875 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18876 | |
| 18877 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18878 | auto trans1 = |
| 18879 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18880 | |
| 18881 | TestCompletionCallback callback1; |
| 18882 | |
| 18883 | int rv = trans1->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 18884 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 18885 | |
| 18886 | std::string response_data; |
| 18887 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 18888 | EXPECT_EQ("hello", response_data); |
| 18889 | |
| 18890 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18891 | |
| 18892 | auto trans2 = |
| 18893 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18894 | |
| 18895 | TestCompletionCallback callback2; |
| 18896 | |
| 18897 | rv = trans2->Start(&request_, callback2.callback(), NetLogWithSource()); |
| 18898 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 18899 | |
| 18900 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 18901 | EXPECT_EQ("world", response_data); |
| 18902 | |
| 18903 | trans1.reset(); |
| 18904 | trans2.reset(); |
| 18905 | |
| 18906 | // One 200 report from first request, then a 408 report from |
| 18907 | // the second request, then a 200 report from the successful retry. |
| 18908 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 18909 | |
| 18910 | // Check error report contents |
| 18911 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 18912 | CheckReport(1 /* index */, 408 /* status_code */, OK); |
| 18913 | CheckReport(2 /* index */, 200 /* status_code */, OK); |
| 18914 | } |
| 18915 | |
| 18916 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18917 | CreateReportRetry421WithoutConnectionPooling) { |
| 18918 | // Two hosts resolve to the same IP address. |
| 18919 | const std::string ip_addr = "1.2.3.4"; |
| 18920 | IPAddress ip; |
| 18921 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 18922 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 18923 | |
| 18924 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
| 18925 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 18926 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 18927 | |
| 18928 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18929 | |
| 18930 | // Two requests on the first connection. |
| 18931 | spdy::SpdySerializedFrame req1( |
| 18932 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 18933 | spdy_util_.UpdateWithStreamDestruction(1); |
| 18934 | spdy::SpdySerializedFrame req2( |
| 18935 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 18936 | spdy::SpdySerializedFrame rst( |
| 18937 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
| 18938 | MockWrite writes1[] = { |
| 18939 | CreateMockWrite(req1, 0), |
| 18940 | CreateMockWrite(req2, 3), |
| 18941 | CreateMockWrite(rst, 6), |
| 18942 | }; |
| 18943 | |
| 18944 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 18945 | spdy::SpdySerializedFrame resp1( |
| 18946 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 18947 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 18948 | spdy::SpdyHeaderBlock response_headers; |
| 18949 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 18950 | spdy::SpdySerializedFrame resp2( |
| 18951 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 18952 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 18953 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 18954 | |
| 18955 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 18956 | SequencedSocketData data1(connect1, reads1, writes1); |
| 18957 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18958 | |
| 18959 | AddSSLSocketData(); |
| 18960 | |
| 18961 | // Retry the second request on a second connection. |
| 18962 | SpdyTestUtil spdy_util2; |
| 18963 | spdy::SpdySerializedFrame req3( |
| 18964 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 18965 | MockWrite writes2[] = { |
| 18966 | CreateMockWrite(req3, 0), |
| 18967 | }; |
| 18968 | |
| 18969 | spdy::SpdySerializedFrame resp3( |
| 18970 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 18971 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 18972 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 18973 | MockRead(ASYNC, 0, 3)}; |
| 18974 | |
| 18975 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 18976 | SequencedSocketData data2(connect2, reads2, writes2); |
| 18977 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18978 | |
| 18979 | AddSSLSocketData(); |
| 18980 | |
| 18981 | // Preload mail.example.org into HostCache. |
| 18982 | HostPortPair host_port("mail.example.org", 443); |
| 18983 | HostResolver::RequestInfo resolve_info(host_port); |
| 18984 | AddressList ignored; |
| 18985 | std::unique_ptr<HostResolver::Request> request; |
| 18986 | TestCompletionCallback callback; |
| 18987 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 18988 | &ignored, callback.callback(), |
| 18989 | &request, NetLogWithSource()); |
| 18990 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18991 | |
| 18992 | HttpRequestInfo request1; |
| 18993 | request1.method = "GET"; |
| 18994 | request1.url = GURL("https://www.example.org/"); |
| 18995 | request1.load_flags = 0; |
| 18996 | request1.traffic_annotation = |
| 18997 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18998 | auto trans1 = |
| 18999 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19000 | |
| 19001 | rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 19002 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19003 | |
| 19004 | const HttpResponseInfo* response = trans1->GetResponseInfo(); |
| 19005 | ASSERT_TRUE(response); |
| 19006 | ASSERT_TRUE(response->headers); |
| 19007 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 19008 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 19009 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 19010 | std::string response_data; |
| 19011 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 19012 | EXPECT_EQ("hello!", response_data); |
| 19013 | |
| 19014 | trans1.reset(); |
| 19015 | |
| 19016 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19017 | |
| 19018 | HttpRequestInfo request2; |
| 19019 | request2.method = "GET"; |
| 19020 | request2.url = GURL("https://mail.example.org/"); |
| 19021 | request2.load_flags = 0; |
| 19022 | request2.traffic_annotation = |
| 19023 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19024 | auto trans2 = |
| 19025 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19026 | |
| 19027 | BoundTestNetLog log; |
| 19028 | rv = trans2->Start(&request2, callback.callback(), log.bound()); |
| 19029 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19030 | |
| 19031 | response = trans2->GetResponseInfo(); |
| 19032 | ASSERT_TRUE(response); |
| 19033 | ASSERT_TRUE(response->headers); |
| 19034 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 19035 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 19036 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 19037 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 19038 | EXPECT_EQ("hello!", response_data); |
| 19039 | |
| 19040 | trans2.reset(); |
| 19041 | |
| 19042 | // One 200 report from the first request, then a 421 report from the |
| 19043 | // second request, then a 200 report from the successful retry. |
| 19044 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 19045 | |
| 19046 | // Check error report contents |
| 19047 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 19048 | network_error_logging_service()->errors()[0]; |
| 19049 | EXPECT_EQ(GURL("https://www.example.org/"), error1.uri); |
| 19050 | EXPECT_TRUE(error1.referrer.is_empty()); |
| 19051 | EXPECT_EQ("", error1.user_agent); |
| 19052 | EXPECT_EQ(ip, error1.server_ip); |
| 19053 | EXPECT_EQ("h2", error1.protocol); |
| 19054 | EXPECT_EQ("GET", error1.method); |
| 19055 | EXPECT_EQ(200, error1.status_code); |
| 19056 | EXPECT_EQ(OK, error1.type); |
| 19057 | EXPECT_EQ(0, error1.reporting_upload_depth); |
| 19058 | |
| 19059 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 19060 | network_error_logging_service()->errors()[1]; |
| 19061 | EXPECT_EQ(GURL("https://mail.example.org/"), error2.uri); |
| 19062 | EXPECT_TRUE(error2.referrer.is_empty()); |
| 19063 | EXPECT_EQ("", error2.user_agent); |
| 19064 | EXPECT_EQ(ip, error2.server_ip); |
| 19065 | EXPECT_EQ("h2", error2.protocol); |
| 19066 | EXPECT_EQ("GET", error2.method); |
| 19067 | EXPECT_EQ(421, error2.status_code); |
| 19068 | EXPECT_EQ(OK, error2.type); |
| 19069 | EXPECT_EQ(0, error2.reporting_upload_depth); |
| 19070 | |
| 19071 | const NetworkErrorLoggingService::RequestDetails& error3 = |
| 19072 | network_error_logging_service()->errors()[2]; |
| 19073 | EXPECT_EQ(GURL("https://mail.example.org/"), error3.uri); |
| 19074 | EXPECT_TRUE(error3.referrer.is_empty()); |
| 19075 | EXPECT_EQ("", error3.user_agent); |
| 19076 | EXPECT_EQ(ip, error3.server_ip); |
| 19077 | EXPECT_EQ("h2", error3.protocol); |
| 19078 | EXPECT_EQ("GET", error3.method); |
| 19079 | EXPECT_EQ(200, error3.status_code); |
| 19080 | EXPECT_EQ(OK, error3.type); |
| 19081 | EXPECT_EQ(0, error3.reporting_upload_depth); |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19082 | } |
| 19083 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19084 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, DontCreateReportHttp) { |
| 19085 | base::HistogramTester histograms; |
| 19086 | RequestPolicy(); |
| 19087 | EXPECT_EQ(1u, network_error_logging_service()->headers().size()); |
| 19088 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19089 | |
| 19090 | // Make HTTP request |
| 19091 | std::string extra_header_string = extra_headers_.ToString(); |
| 19092 | MockRead data_reads[] = { |
| 19093 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 19094 | MockRead("hello world"), |
| 19095 | MockRead(SYNCHRONOUS, OK), |
| 19096 | }; |
| 19097 | MockWrite data_writes[] = { |
| 19098 | MockWrite("GET / HTTP/1.1\r\n" |
| 19099 | "Host: www.example.org\r\n" |
| 19100 | "Connection: keep-alive\r\n"), |
| 19101 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19102 | }; |
| 19103 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19104 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 19105 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 19106 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19107 | // Insecure url |
| 19108 | url_ = "http://www.example.org/"; |
| 19109 | request_.url = GURL(url_); |
| 19110 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19111 | TestCompletionCallback callback; |
| 19112 | auto session = CreateSession(&session_deps_); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19113 | auto trans = |
| 19114 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19115 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19116 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19117 | |
| 19118 | std::string response_data; |
| 19119 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19120 | EXPECT_EQ("hello world", response_data); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19121 | |
| 19122 | // Insecure request does not generate a report |
| 19123 | histograms.ExpectBucketCount( |
| 19124 | NetworkErrorLoggingService::kRequestOutcomeHistogram, |
| 19125 | NetworkErrorLoggingService::RequestOutcome::DISCARDED_INSECURE_ORIGIN, 1); |
| 19126 | |
| 19127 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19128 | } |
| 19129 | |
| 19130 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19131 | DontCreateReportHttpError) { |
| 19132 | base::HistogramTester histograms; |
| 19133 | RequestPolicy(); |
| 19134 | EXPECT_EQ(1u, network_error_logging_service()->headers().size()); |
| 19135 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19136 | |
| 19137 | // Make HTTP request that fails |
| 19138 | MockRead data_reads[] = { |
| 19139 | MockRead("hello world"), |
| 19140 | MockRead(SYNCHRONOUS, OK), |
| 19141 | }; |
| 19142 | |
| 19143 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
| 19144 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19145 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19146 | url_ = "http://www.originwithoutpolicy.com:2000/"; |
| 19147 | request_.url = GURL(url_); |
| 19148 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19149 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19150 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19151 | auto trans = |
| 19152 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19153 | TestCompletionCallback callback; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19154 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19155 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 19156 | |
| 19157 | // Insecure request does not generate a report, regardless of existence of a |
| 19158 | // policy for the origin. |
| 19159 | histograms.ExpectBucketCount( |
| 19160 | NetworkErrorLoggingService::kRequestOutcomeHistogram, |
| 19161 | NetworkErrorLoggingService::RequestOutcome::DISCARDED_INSECURE_ORIGIN, 1); |
| 19162 | |
| 19163 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19164 | } |
| 19165 | |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19166 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19167 | ReportContainsUploadDepth) { |
| 19168 | reporting_upload_depth_ = 7; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19169 | request_.reporting_upload_depth = reporting_upload_depth_; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19170 | RequestPolicy(); |
| 19171 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19172 | const NetworkErrorLoggingService::RequestDetails& error = |
| 19173 | network_error_logging_service()->errors()[0]; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19174 | EXPECT_EQ(7, error.reporting_upload_depth); |
| 19175 | } |
| 19176 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19177 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ReportElapsedTime) { |
| 19178 | std::string extra_header_string = extra_headers_.ToString(); |
| 19179 | static const base::TimeDelta kSleepDuration = |
| 19180 | base::TimeDelta::FromMilliseconds(10); |
| 19181 | |
| 19182 | std::vector<MockWrite> data_writes = { |
| 19183 | MockWrite(ASYNC, 0, |
| 19184 | "GET / HTTP/1.1\r\n" |
| 19185 | "Host: www.example.org\r\n" |
| 19186 | "Connection: keep-alive\r\n"), |
| 19187 | MockWrite(ASYNC, 1, extra_header_string.data()), |
| 19188 | }; |
| 19189 | |
| 19190 | std::vector<MockRead> data_reads = { |
| 19191 | // Write one byte of the status line, followed by a pause. |
| 19192 | MockRead(ASYNC, 2, "H"), |
| 19193 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 19194 | MockRead(ASYNC, 4, "TTP/1.1 200 OK\r\n\r\n"), |
| 19195 | MockRead(ASYNC, 5, "hello world"), |
| 19196 | MockRead(SYNCHRONOUS, OK, 6), |
| 19197 | }; |
| 19198 | |
| 19199 | SequencedSocketData data(data_reads, data_writes); |
| 19200 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19201 | |
| 19202 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19203 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19204 | |
| 19205 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19206 | |
| 19207 | auto trans = |
| 19208 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19209 | |
| 19210 | TestCompletionCallback callback; |
| 19211 | |
| 19212 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19213 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19214 | |
| 19215 | data.RunUntilPaused(); |
| 19216 | ASSERT_TRUE(data.IsPaused()); |
| 19217 | FastForwardBy(kSleepDuration); |
| 19218 | data.Resume(); |
| 19219 | |
| 19220 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19221 | |
| 19222 | std::string response_data; |
| 19223 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19224 | EXPECT_EQ("hello world", response_data); |
| 19225 | |
| 19226 | trans.reset(); |
| 19227 | |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19228 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19229 | |
| 19230 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19231 | |
| 19232 | const NetworkErrorLoggingService::RequestDetails& error = |
| 19233 | network_error_logging_service()->errors()[0]; |
| 19234 | |
| 19235 | // Sanity-check elapsed time in error report |
| 19236 | EXPECT_EQ(kSleepDuration, error.elapsed_time); |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19237 | } |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19238 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19239 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 19240 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 19241 | } // namespace net |